Thursday, August 13, 2015

Get Server Hardware specs–PowerShell

 

 

This script loops through a text list and get information using Get-WmiObject. Then dumps it to an array then to a Grid View.

 

 

# Get Server Hardware specs

# 2015 Edward

# CPU / RAM / Disk Size / IP Address

 

 

 

 

##### Set Variables #######

$fileCount = 0

$List = @()

$i = 0

 

 

 

#get the list of servers to scan from serverlist.txt

$serverlist = "C:\scripts\computers.txt"

 

 

 

 

#get the count of servers for updates to the user.

 

$fileCount = (Get-Content $serverlist | Measure-Object).Count

 

 

 

#Loop the server list.

foreach ($server in Get-Content $serverlist) {

 

#increment the number of records proccessed

$i++

 

#Write to the screen whats happening.

Write-Progress -activity "Connecting to server $server" -status "Scanning: $i of $($fileCount)" -percentComplete (($i / $fileCount)  * 100)

 

#do a try if there is an issue spit out the error.

try {

 

    #IF there is an error stop and go to the next record.

    $ErrorActionPreference = 'Stop'

       

    $bios = Get-WmiObject Win32_BIOS -ComputerName $server

    Write-Progress -activity "Scanning server $server -  getting BIOS information" -status "Scanning: $i of $($fileCount)" -percentComplete (($i / $fileCount)  * 100)

 

    Write-Progress -activity "Scanning server $server - getting Processor information" -status "Scanning: $i of $($fileCount)" -percentComplete (($i / $fileCount)  * 100)

    $Proc = Get-WmiObject Win32_processor -ComputerName $server | Select-Object -First 1

   

 

    Write-Progress -activity "Scanning server $server - getting Memory information" -status "Scanning: $i of $($fileCount)" -percentComplete (($i / $fileCount)  * 100)

    $memory = Get-WmiObject Win32_physicalmemory -ComputerName $server

   

 

    Write-Progress -activity "Scanning server $server - getting System information" -status "Scanning: $i of $($fileCount)" -percentComplete (($i / $fileCount)  * 100)

    $system= Get-WmiObject Win32_ComputerSystem -ComputerName $server

   

 

    Write-Progress -activity "Scanning server $server - getting Disk information" -status "Scanning: $i of $($fileCount)" -percentComplete (($i / $fileCount)  * 100)

    $disks = Get-WmiObject -class Win32_LogicalDisk -ComputerName $server -Filter {DriveType=3}

   

 

 

    $disklist = " "

    foreach ($disk in $disks) {

        IF ($disklist -eq " "){$putAcomma = ""} ELSE {$putAcomma = ", "}  

        $size = [math]::Round(([int64]$disk.Size / 1073741824))

        $disklist = $disklist + $putAcomma + $disk.DeviceID + " " + [string]$size + " GB"

    }

    Write-Progress -activity "Scanning server $server" -status "Scanning: $i of $($fileCount)" -percentComplete (($i / $fileCount)  * 100)

 

 

    #Set the array for the output.

 

    $List += [pscustomobject]@{

    'ComputerName'         = $server

    'Manufacturer'        = $bios.Manufacturer

    'Model'               = $system.Model

    'BIOS Version'        = $bios.Version

    'Serial Number'       = $bios.SerialNumber

    'Processor Number'    = $system.NumberOfProcessors

    'Processor Name'      = $proc.name

    'CPUs'                 = $system.NumberOfLogicalProcessors

    'Speed (MHZ)'          = $proc.CurrentClockSpeed

    'RAM (GB)'             = $system.TotalPhysicalMemory / 1GB -as [int]

    'Used RAM slot'       = $memory.count

    'DiskList'             = $disklist

    }

 

    } catch {

    $List += [pscustomobject]@{

    'ComputerName'         = $server

    'CPUs'                 = " ERROR "

    'Speed (MHZ)'          = " ERROR "

    'RAM (GB)'             = " ERROR "

    'DiskList'             = $error[0].exception

    }

  }

 

}

 

write-progress -activity "Completed."

$List | Out-GridView

 

 

No comments:

Post a Comment