none
Transfer results to csv RRS feed

  • Question

  • Hi Script Guys!

    Long time reader, first time questioner!

    I have this script that tells me the model numbers and serials of multiple PC's from a .txt file and it outputs the results below the script. We are currently re-asset tagging the school. Over 1000s PCs and Monitors and could really do with this script outputting to .csv or an excel spread sheet with simple column headings. Can you guys help?!

    $ArrComputers = 'localhost'
    $OutputLog = ".\output.log" # Main log
    $NotRespondingLog = ".\notresponding.log" # Logging "unqueried" hosts

    $ErrorActionPreference = "Stop" # Or add '-EA Stop' to Get-WmiObject queries
    Clear-Host

    foreach ($computer in (Get-Content 'C:\CommandShellPrompts\L54-PCs.txt')) 
    {
        try
        {
            $computerSystem = get-wmiobject Win32_ComputerSystem -Computer $Computer
            $computerBIOS = get-wmiobject Win32_BIOS -Computer $Computer
            $Version = Get-WmiObject -Namespace "Root\CIMv2" `
                -Query "Select * from Win32_ComputerSystemProduct" `
                -computer $computer | select -ExpandProperty version
            $MonitorInfo = gwmi WmiMonitorID -Namespace root\wmi `
                -computername $Computer `
                | Select PSComputerName, `
                    @{n="Model";e={[System.Text.Encoding]::ASCII.GetString(`
                        $_.UserFriendlyName -ne 00)}},
                    @{n="Serial Number";e={[System.Text.Encoding]::ASCII.GetString(`
                        $_.SerialNumberID -ne 00)}}     
        }
        catch
        {
            $Computer | Out-File -FilePath $NotRespondingLog -Append -Encoding UTF8
            continue
        }

        $Header = "System Information for: {0}" -f $computerSystem.Name

        # Outputting and logging header.
        write-host $Header -BackgroundColor DarkCyan
        $Header | Out-File -FilePath $OutputLog -Append -Encoding UTF8

        $Output = (@"
    -------------------------------------------------------

    Model          : {0} 
    Serial Number  : {1} 
    Version        : {2} 
    Monitor Model  : {3}
    Monitor Serial : {4}

    -------------------------------------------------------

    "@) -f $computerSystem.Model, $computerBIOS.SerialNumber, $Version, `
           $MonitorInfo.Model, $MonitorInfo."Serial Number"

        # Ouputting and logging WMI data
        Write-Host $Output
        $Output | Out-File -FilePath $OutputLog -Append -Encoding UTF8
    }
     

    • Moved by Bill_Stewart Tuesday, November 7, 2017 9:42 PM This is not "fix/debug/rewrite my script for me" forum
    Thursday, September 14, 2017 9:00 AM

All replies