Why doesn't out-File write to a file?

Welcome Forums General PowerShell Q&A Why doesn't out-File write to a file?

Viewing 5 reply threads
  • Author
    Posts
    • #183375
      Participant
      Topics: 2
      Replies: 4
      Points: 1
      Rank: Member

      I have a script that I can’t get the output to write to a file.  This is the script:

    • #183393
      Participant
      Topics: 11
      Replies: 127
      Points: 764
      Helping Hand
      Rank: Major Contributor

      It would be beneficial if you can repost your code as per https://powershell.org/forums/topic/read-me-before-posting-youll-be-glad-you-did/ so it’s more readable and you can get a quicker answer.

    • #183429
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      I ran your script – of course with another output path and of course without the remove cmdlets but I’ve just got the expected output written to the output file I specified.
      Do you get errors?

    • #183663
      Participant
      Topics: 2
      Replies: 4
      Points: 1
      Rank: Member

      Thank you for running the script.

      I don’t get any errors.  It doesn’t create the output file.  And If I create a blank file it doesn’t write to it.

      Do you have any idea how I could figure out what the problem is?

      Thanks,

    • #183675
      Participant
      Topics: 11
      Replies: 127
      Points: 764
      Helping Hand
      Rank: Major Contributor

      What if you try to manually create the file in the same path using New-Item and pipe a simple string to it?

      Try using some try/catch around Remove-AppxProvisionedPackage ... | ...

    • #183678
      Senior Moderator
      Topics: 10
      Replies: 164
      Points: 880
      Helping Hand
      Rank: Major Contributor

      Potential problems:
      Location – Is E:\ a local drive, or a network drive? If it is a network drive, you may have to tell PowerShell where it is, like this: https://stackoverflow.com/questions/4742992/cannot-access-network-drive-in-powershell-running-as-administrator Also, consider testing your script with a different output location, such as ~\test.txt (local user directory).
      Permissions – Have you verified that the user account running the script definitely has permission to write files at the target location? Permissions cause headaches all the time.

      If those things seem fine, try setting this:

      and then re-run your script. Reading through the output should tell you what is and isn’t happening while your script executes.

Viewing 5 reply threads
  • The topic ‘Why doesn't out-File write to a file?’ is closed to new replies.