Get-Random from a Document, turn it into variable, then delete it, resave

Welcome Forums General PowerShell Q&A Get-Random from a Document, turn it into variable, then delete it, resave

Viewing 1 reply thread
  • Author
    Posts
    • #244301
      Participant
      Topics: 5
      Replies: 10
      Points: 87
      Rank: Member

      Essentially want to have a document (random.txt) that will have a list of values in it. It will grab the random line, store it in a variable, display it, then remove it (by re-saving the document appears to be the best method I’ve found).

      Rinse and repeat.

      My method removes everything. I’ve tried permutations of it, and it doesn’t help.

    • #247056
      Participant
      Topics: 0
      Replies: 38
      Points: 379
      Helping Hand
      Rank: Contributor

      Hello ALombardi01,

      This is expected behavior when you have Get-Content and Out-file in same pipeline.

      You have two options:

      1. Output result to different file
      2. Get-Content of the file and save it in variable and then Out-file it to same file.

      Reference: https://rakhesh.com/powershell/get-content-and-out-file-in-the-same-pipeline/

      Hope that helps.

Viewing 1 reply thread
  • You must be logged in to reply to this topic.