2017-09-20 103 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格式显示结果。