Monday Morning Formatting - PSCustomobject

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Mark Prior Mark Prior 4 months, 2 weeks ago.

  • Author
    Posts
  • #48083
    Profile photo of Mark Prior
    Mark Prior
    Participant

    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 4 months, 2 weeks ago by Profile photo of Mark Prior Mark Prior.
  • #48086
    Profile photo of Christian Sandfeld
    Christian Sandfeld
    Participant

    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
    
  • #48088
    Profile photo of Mark Prior
    Mark Prior
    Participant

    Many thanks Christian, worked great

You must be logged in to reply to this topic.