cls
$pc = Get-Content "c:\temp\tmp\XP_I_Can_Ping.txt"
$results = @()
foreach ($machine in $pc)
{
$computerName = Get-WMIObject -class Win32_ComputerSystem -computername $machine | Select-Object -ExpandProperty name
$computerOS = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $machine | Select-Object -ExpandProperty version
$getip = ([version](Test-Connection $machine -Count 1).IPV4Address.IPAddressToString).Build;
$desc = (Get-ADComputer $machine -Properties Description).description #this is cleaner in the output
$results += New-Object PSObject -Property:@{PCName=$computerName;'OS Version'=$ComputerOS;'IP vLan'=$getip;'Description'=$desc}
}
$results | Export-Csv c:\temp\tmp\XPOutput.csv
The above code works and does what I want. But I have a question on the output. I get $computername, $computeros, $getip, $desc and in my $results line I have them setup in the same order. yet my XPOutput.CSV file has them in this order. OS Version, Description, PCName, IP. How come? I did not see any Sort switch on New-Object so how do you sort them in the order you want?