Powershell command with redirect to a file works sometimes but not all the time

Welcome Forums General PowerShell Q&A Powershell command with redirect to a file works sometimes but not all the time

Viewing 3 reply threads
  • Author
    Posts
    • #230128
      Participant
      Topics: 1
      Replies: 0
      Points: 11
      Rank: Member

      This is the first time I’ve used powershell.  I’m using it in what I think is a basic mode.  I’m issuing a command, redirecting the output to a file and then reading the file for the information.

      The users in our company use a terminal emulator program (on Windows 10) to access our cloud system.  The emulator happens to be AccuTerm.  My ultimate goal is to issue a command that will return the external IP address.  I’m using the following command to redirect output to a text file where I can parse it and pull out the IP address.  The command is

      PowerShell -Command Invoke-WebRequest ifconfig.me/ip > “C:\ABC123\External.IP.txt”

      The command actually works great…from my pc.  Everytime I execute it here it returns the IP address perfectly.  When I released it to other users, it will work for some, and not for others.  And if I go to a PC that didn’t give proper results I notice that the text file that is produced is blank.  And to make matters more confusing, while testing it on a PC that didn’t work, all of a sudden it will start working perfectly and will keep working right.  I don’t know if this is a coincidence or not but when I restarted this one particular PC that wasn’t giving the proper results at first but then started to give the proper results, it stopped working again after restarting.

      I have a feeling that there is some basic concept that I’m missing here.  Any help would be greatly appreciated.

    • #230137
      Participant
      Topics: 9
      Replies: 678
      Points: 2,683
      Helping Hand
      Rank: Community Hero
    • #230143
      Participant
      Topics: 12
      Replies: 542
      Points: 1,319
      Helping Hand
      Rank: Community Hero

      Get-MyWANIP function added to AZSBTools PowerShell module

    • #230152
      Participant
      Topics: 1
      Replies: 55
      Points: 526
      Helping Hand
      Rank: Major Contributor
      • This reply was modified 6 months, 2 weeks ago by AndySvints.
Viewing 3 reply threads
  • The topic ‘Powershell command with redirect to a file works sometimes but not all the time’ is closed to new replies.