Powershell output blank on 1 computer but not on other

57 Views Asked by At

I wrote some code to return the ip address of the local computer. Basically I created a powershell script which has just 1 line of code in it:

Invoke-RestMethod -Uri ('https://ipinfo.io/')

Then in vba, I use WScript host to run the file, then read the StdOut. From this I look for the line with the ip, do some stripping and return the bare ip. All good and well on the first computer that I tried it on but on the next, which is where it is really needed, the return of StdOut is empty, and if I open powershell and run that same command, I do get the expected info. Can anyone here tell me why this is. The vba code is pretty simple:

Function IPGet()
    Dim Wsh As Object, WExec As Object
    Dim Result$, cmd$, LT$
    Dim Cnt%, i%
    
    cmd = "Powershell -file ""c:\working\access\all county\scripts\IpInfo.ps1"""
    Set Wsh = CreateObject("WScript.Shell")
    Set WExec = Wsh.exec(cmd)
    Result = WExec.StdOut.ReadAll
    Cnt = StringListGetCount(Result, vbCrLf)                'This is just an old function that returns a number telling how many items are listed 
    
    For i = 1 To Cnt
        LT = Trim(StringListGetItem(Result, i, vbCrLf))     'This is just an old function that returns the item at the specified position in a delimited list
        
        If LT Like "ip*:*" Then
            IPGet = Trim(Mid(LT, InStr(1, LT, ":") + 1))
            Exit For
        End If
    Next
End Function
0

There are 0 best solutions below