2017-09-20 115 views
1

我想在一個CSV或TXT結果從下面的PowerShell命令列出:PowerShell的名單成績

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 

我確實看到結果,但希望有一個列出服務器名稱的文件,以及它是否具有代理服務器的天氣。

 
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). 

回答

2

解析命令輸出到自定義對象(你不需要Invoke-Expression運行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'} 
} 

結果然後可以導出爲CSV:

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

或處理中無論你喜歡什麼其他方式。

0

您可以嘗試類似Invoke-Command -filepath C:\temp\Show_Proxy.ps1 -cn $ServerList | Export-Csv -NoTypeInformation -Path results.csv的結果以CSV格式顯示結果。