Author Posts

July 25, 2016 at 9:24 am

Hi All

i have the below going out and poking a list of servers to see what OS is installed, all working fine however when i push out to a csv it is not in columns but all held as text in a single column

###############
##Get Servers##
###############

$servers = Get-Content "\\eurorchestrator\c$\servers2.csv"

###########
##Command##
###########

$output = foreach ($server in $servers)
{
    $operating = (Get-WmiObject -class Win32_OperatingSystem -computername $server).name
    

[pscustomobject]@{

'Computername' = "$Server"
'OSVersion' = "$operating"

} 

}

#################
##Build Results##
#################

$output |ft computername, osversion -AutoSize | Out-File "\\eurorchestrator\c$\serversResults.csv" 

Im After column A "Compuetername" Column B "OSVersion"

Thanks

  • This topic was modified 2 years ago by  Mark Prior.

July 25, 2016 at 10:06 am

Hi Mark,

Substitute line 29 with this and you should get what you're after.

$output | Export-Csv -Path \\path\to\file.csv -NoTypeInformation -UseCulture

July 25, 2016 at 10:18 am

Many thanks Christian, worked great