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
    • #230128
      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
      Topics: 3
      Replies: 340
      Points: 1,120
      Helping Hand
      Rank: Community Hero
    • #230143
      Topics: 12
      Replies: 523
      Points: 1,214
      Helping Hand
      Rank: Community Hero

      Get-MyWANIP function added to AZSBTools PowerShell module

      [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 # PowerShellGallery dropped Ssl3 and Tls as of 1 April 2020
      Install-Module AZSBTools 
    • #230152
      Topics: 0
      Replies: 14
      Points: 175
      Helping Hand
      Rank: Participant
      $IPObj=Invoke-RestMethod -Uri 'https://api.ipify.org?format=json'
      • This reply was modified 1 week, 3 days ago by AndySvints.
Viewing 3 reply threads
  • You must be logged in to reply to this topic.