Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

results of Invoke-Command to csv

$
0
0

I'm writing a script that's to get me some info from remote network adapters. In short it goes like this

$PCs = @("pc1";"pc2";....)

foreach($PC in $PCs){

Invoke-command -computerName $PC -ScriptBlock{

$name = get-NetAdapterHardwareInfo | select -expandProperty Name;

$vlan = get-NetAdapterAdvancedProperty | Select DisplayName, DisplayValue | where {$_.Displayname -like "vlan*"} | select -expandProperty DisplayValue;

$output = @{};

$output.PC = $env:computername;

$output.name = $name;

$output.vlan = $vlan;

$netInfo += New-Object psobject -property $output

}

$netInfo |  Export-csv c:\nicInfo.csv -notypeInformation -append

}

I get the info I need if I add Write-Host to display my variables yet I don't get the csv as I need. Can someone please review and put me on the right path. I think the problem might be that my variables don't live outside of Invoke-Command but if so how do I get them out?

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles