PowerShell列表结果
我试图在CSV或txt中列出以下PowerShell命令的结果:PowerShell列表结果,powershell,proxy,output,invoke-command,Powershell,Proxy,Output,Invoke Command,我试图在CSV或txt中列出以下PowerShell命令的结果: Show_Proxy.ps1: Invoke-Expression "netsh winhttp show proxy" Server\u Name.txt: Server01 Server02 Server03 我确实看到了结果,但希望有一个文件列出服务器名称和它是否有代理服务器 PS C:\Windows> $ServerList= Get-Content C:\temp\Server_Names.txt PS C:\Win
Show_Proxy.ps1
:
Invoke-Expression "netsh winhttp show proxy"
Server\u Name.txt
:
Server01
Server02
Server03
我确实看到了结果,但希望有一个文件列出服务器名称和它是否有代理服务器
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).
PS C:\Windows>$ServerList=获取内容C:\temp\Server\u Names.txt
PS C:\Windows>Invoke命令-FilePath C:\temp\Show\u Proxy.ps1-CN$ServerList
当前WinHTTP代理设置:
代理服务器:代理服务器名称:8080
旁路列表:
当前WinHTTP代理设置:
代理服务器:代理服务器名称:8080
旁路列表:
当前WinHTTP代理设置:
直接访问(无代理服务器)。
您可以尝试类似于
Invoke Command-filepath C:\temp\Show_Proxy.ps1-cn$ServerList | Export Csv-NoTypeInformation-Path results.Csv
将结果抛出到Csv中。将命令输出解析为自定义对象(运行netsh
不需要调用表达式
):
然后可以将结果导出到CSV:
Invoke-Command -FilePath 'C:\path\to\your.ps1' -ComputerName $ServerList |
Export-Csv 'C:\path\to\output.csv'
或者以你喜欢的其他方式处理
$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'}
}
Invoke-Command -FilePath 'C:\path\to\your.ps1' -ComputerName $ServerList |
Export-Csv 'C:\path\to\output.csv'