Write-Output Question(s)

Welcome Forums General PowerShell Q&A Write-Output Question(s)

Viewing 1 reply thread
  • Author
    Posts
    • #285229
      Participant
      Topics: 8
      Replies: 23
      Points: 104
      Rank: Participant

      Hi All still learning so bare with me here.

      I am trying to test-path and if the results it true or false out to that to a text file.

      Basically what I am wanting to be returned in the text file is the device name that the path was tested next to the response (true or false).

      I am using this script to do the testing of the path:
      $servers = get-content -path “C:\Temp\servers.txt”
      $destination = “\\$server\c$\Windows”
      foreach ($server in $servers) {}
      # The following section checks to see if there is a TEMP folder on the server and if not, it creates one.
      If(Test-Path -Path $destination) { “true” } Else { “false” } Write-Output Out-File -FilePath C:\Temp\testconnection.txt

       

      When I check the testconnection.txt file there is no data shown.  However on my PowerShell console I see the following

       

      PS C:\Users\xxxxxxx> $servers = get-content -path “C:\Temp\servers.txt”
      $destination = “\\$server\c$\Windows”
      foreach ($server in $servers) {}
      # The following section checks to see if there is a TEMP folder on the server and if not, it creates one.
      If(Test-Path -Path $destination) { “true” } Else { “false” } Out-File -FilePath C:\Temp\testconnection.txt

      ##if(!(Test-Path -Path $destination )){
      false

      FYI there are 5 devices in the server.txt file to run the test-path on.

      Can anyone tell me how to get the results of the test to be added to the testconnection.txt file?

    • #285250
      Participant
      Topics: 5
      Replies: 253
      Points: 1,007
      Helping Hand
      Rank: Community Hero

      I’m a little confused on what you are trying to do.  You foreach loop has nothing in it {}.  Are you wanting to check for the existence of a path on remote machines and putting the results in a txt file on your local machine?  It seems like what you said, but the comments in your code mentioned creating a folder.  Here is a basic script that checks for “C:\Windows\Temp” on remote machines, although if they are windows I would expect this to always be true.  Maybe it will help.  Otherwise, please clarify what you want to do.

       

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