2017-09-20 1 views
1

Je suis en train de la liste dans un fichier CSV ou txt les résultats de la commande PowerShell suivante:Liste PowerShell Résultats

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 

Je vois les résultats, mais aimerait avoir un fichier répertoriant le nom du serveur et la météo, il a un serveur proxy ou non.

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

Répondre

2

Parse la sortie de commande en objets personnalisés (vous n'avez pas besoin Invoke-Expression pour la course 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'} 
} 

Le résultat peut ensuite être exporté vers un fichier CSV:

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

ou traitées quelle que soit l'autre manière que vous aimez.

0

Vous pouvez essayer quelque chose comme Invoke-Command -filepath C:\temp\Show_Proxy.ps1 -cn $ServerList | Export-Csv -NoTypeInformation -Path results.csv de jeter un résultat dans un fichier CSV.