PowerShell

PowerShell – Ping all SCCM servers

Part of daily environment health checks is to verify that all SCCM infrastructure servers are reachable on the network.  Usually you can verify this by viewing the Monitoring tab in the SCCM console, but in cases where you have multiple standalone distribution point devices you may want to simply ping them to check their availability.  This PowerShell script will help you to do this task without having to write a batch file to ping each device.

# Script to ping all SCCM servers

$ServerName = “SERVERNAME1”, “SERVERNAME2”, “SERVERNAME3”, “SERVERNAME4”

foreach ($Server in $ServerName) {
if (test-Connection -ComputerName $Server -Count 2 -Quiet ) {
write-Host “$Server is online ” -ForegroundColor Green
} else
{ Write-Warning “$Server is offline ”
}
}

 

PowerShell – Manage SCCM Inbox counts

A good practice in SCCM is to check your Inbox folder file counts daily for any backlog that may point to a potential component problem.  This task is easily achieved through a simple PowerShell command.  The SMS_Inbox_Monitor information is found in WMI.  If you would like to get an Inbox file count you can run the following PowerShell command.

Get-WmiObject -Class Win32_PerfFormattedData_SMSINBOXMONITOR_SMSInbox -ComputerName SERVERNAME1, SERVERNAME2, SERVERNAME3 | Select-Object -Property PSComputerName, Name, FileCurrentCount

This will work for both SCCM 2007 and SCCM 2012.  I like to save this information to my SQL database so that I can keep track of the weekly counts.  Here is a sample script how to import this information into your database.

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# Import SCCM Inbox Counts
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

 

$events = Get-WmiObject -Class Win32_PerfFormattedData_SMSINBOXMONITOR_SMSInbox -ComputerName SERVERNAME1, SERVERNAME2, SERVERNAME3 | Select-Object -Property PSComputerName, Name, FileCurrentCount
$connectionString = “Data Source=SCCM_SQL_SERVER;Integrated Security=true;Initial Catalog=SCCM_Support;”
$bulkCopy = new-object (“Data.SqlClient.SqlBulkCopy”) $connectionString
$bulkCopy.DestinationTableName = “SCCM_Inbox_Count”
$dt = New-Object “System.Data.DataTable”

# build the datatable
$cols = $events | get-member -MemberType NoteProperty | select -Expand Name
foreach ($col in $cols) {$null = $dt.Columns.Add($col)}

foreach ($event in $events)
{
$row = $dt.NewRow()
foreach ($col in $cols) { $row.Item($col) = $event.$col }
$dt.Rows.Add($row)
}

# Write to the database!
$bulkCopy.WriteToServer($dt)