SCOM Mail Report for Pending Management Approvals

In a secure SCOM environment the security setting for “Manual Agent Installation” should always be set to “Review new manual agent installation in pending management view”.
This can lead to devices not being discovered automatically after the servers were build. Yeah people forget something like that from time to time 😉

To avoid this I created a small PowerShell script to create an E-Mail report every morning (Scheduled Task).
Please note that the user account needs to have admin access in SCOM to query the information. The user also must have access to the SMTP server or the server needs to be allowed to relay mails.

The following variables need to be amended:
– PSEmailServer
– ManagementServer
– from
– to

$PSEmailServer = "defineSMTPserver"
$ManagementServer = "defineMGMTserver"
$from = "from@example.com"
$to =  "to@example.com"

Import-Module OperationsManager
$connections = Get-SCOMManagementGroupConnection
if (!$connections){
New-SCOMManagementGroupConnection –ComputerName $ManagementServer
}
$objects = Get-SCOMPendingManagement

if (!$objects){
[string]$emailbody = "No Servers are waiting for Management Approval."
}
else{
[string]$emailbody = "The following Servers are pending Management approval:" + "`r`n"
foreach ($object in $objects){
$emailbody = $emailbody + $object.AgentName + "`r`n"
}
$emailbody = $emailbody + "`r`n" + "`r`n" + "Go to 'Administration > Device Management > Pending Management' to approve/reject the Hosts! "
}

Send-MailMessage -from $from -to $to -Subject "SCOM Pending Management Approval Report" -body $emailbody

Leave a Reply

Your email address will not be published. Required fields are marked *

*