PowerShell: Retrieve all “live” (pingable) Dell server names, models & serial number

Here’s the other script that filters out anything non-Dell- easy enough to modify so it would focus on any manufacturer (I’ve just noticed that this code would GWMI first, then ping. I’ll change this, otherwise it’ll try to retrieve WMI data from a server it can’t reach.)
=============================================================================
Remove-Item .\Dell_Name_ST_Model.csv

[string]$serverList
[string]$serverArray
[int]$xAxis
[int]$yAxis

$serverList = Get-ADComputer -LDAPFilter “(&(ObjectCategory=Computer)(OperatingSystem=*server*))” | Select-Object Name | Sort-Object Name
$serverNames = $serverList.Name

$serverArray = New-Object ‘object[,]’ $serverList.Count,4
$xAxis = 0
$yAxis = 0

ForEach ($server in $serverNames)
{

$madeBy = Get-WMIObject -Class Win32_ComputerSystem -ComputerName $server | Select-Object Manufacturer -ExpandProperty Manufacturer

If($madeBy -eq “Dell Inc.”)
{
$isAlive = Test-Connection $Server -Count 1 -Quiet
If($isAlive -eq $true)
{
Write-Host “Server $server is fine”
$serverArray[$xAxis,$yAxis] = Get-WMIObject -Class Win32_OperatingSystem -ComputerName $server | Select-Object CSName -ExpandProperty CSName
$yAxis++
$serverArray[$xAxis,$yAxis] = Get-WMIObject -Class Win32_ComputerSystem -ComputerName $server | Select-Object Manufacturer -ExpandProperty Manufacturer
$yAxis++
$serverArray[$xAxis,$yAxis] = Get-WMIObject -Class Win32_ComputerSystem -ComputerName $server | Select-Object Model -ExpandProperty Model
$yAxis++
$serverArray[$xAxis,$yAxis] = Get-WMIObject -Class Win32_SystemEnclosure -ComputerName $server | Select-Object SerialNumber -ExpandProperty SerialNumber
}
ElseIf($isAlive -eq $false)
{
Write-Host “Server $server is not responding”
}
}
$yAxis=0
$xAxis++
}

$yAxis=0
$xAxis=0

ForEach($item in $serverArray)
{
$gatherServerArrayContent = $csName = $serverArray[$xAxis,$yAxis]
$gatherServerArrayContent += “,”
$gatherServerArrayContent += $manufacturer = $serverArray[$xAxis,($yAxis+1)]
$gatherServerArrayContent += “,”
$gatherServerArrayContent += $model = $serverArray[$xAxis,($yAxis+2)]
$gatherServerArrayContent += “,”
$gatherServerArrayContent += $serialNumber = $serverArray[$xAxis,($yAxis+3)]

$gatherServerArrayContent | Out-File .\Dell_Name_ST_Model.csv -Append

$yAxis = 0
$xAxis++
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s