1

I'm trying to list in a CSV or txt the results from the following PowerShell command:

Show_Proxy.ps1:

Invoke-Expression "netsh winhttp show proxy"

Server_Name.txt:

Server01
Server02
Server03

$ServerList = Get-Content C:\temp\Server_Names.txt
Invoke-Command -FilePath C:\temp\Show_Proxy.ps1 -CN $ServerList

I do see the results, but would like to have a file listing the server name and weather it has a proxy server or not.

PS C:\Windows> $ServerList= Get-Content C:\temp\Server_Names.txt
PS C:\Windows> Invoke-Command -FilePath C:\temp\Show_Proxy.ps1 -CN $ServerList

Current WinHTTP proxy settings:

    Proxy Server(s) :  Proxy_Server_Name:8080
    Bypass List     :  

Current WinHTTP proxy settings:

    Proxy Server(s) :  Proxy_Server_Name:8080
    Bypass List     :  

Current WinHTTP proxy settings:

    Direct access (no proxy server).
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328

2 Answers2

2

Parse the command output into custom objects (you don't need Invoke-Expression for running netsh):

$output = netsh winhttp show proxy
$null, $proxy = $output -like '*proxy server(s)*' -split ' +: +', 2

New-Object -Type PSObject -Property @{
    'ComputerName' = $env:COMPUTERNAME
    'Proxy'        = if ($proxy) {$proxy} else {'direct'}
}

The result can then be exported to a CSV:

Invoke-Command -FilePath 'C:\path\to\your.ps1' -ComputerName $ServerList |
    Export-Csv 'C:\path\to\output.csv'

or processed in whatever other way you like.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
0

You could try something like Invoke-Command -filepath C:\temp\Show_Proxy.ps1 -cn $ServerList | Export-Csv -NoTypeInformation -Path results.csv to throw a results in a CSV.

0x11
  • 173
  • 8