Powershell snippet – add operators
Posted by wim-ms on April 18, 2008
Some code to automatically add some operator roles. Just edit the hash with your own description and groups. Ofcourse, this code requires that you run it from the Opsmgr command shell, or that you add the PSSnapin
$operatorroles=@{"ISA Operators"="DOMAIN\GS.ISA.admins";"Exchange Operators"="DOMAIN\GS.Exchange.admins";"SQL Operators"="DOMAIN\GS.SQL.admins"}
function addOperatorRole {
param([string]$operatorname)
write-host "adding operator: $operatorname"
$mg=(get-item .).ManagementGroup
$operator=$mg.GetMonitoringProfiles() | where {$_.Name -eq "Operator"}
$obj = new-object Microsoft.EnterpriseManagement.Monitoring.Security.MonitoringUserRole
$obj.Name=$operatorname
$obj.DisplayName=$operatorname
$obj.MonitoringProfile = $operator
$mg.InsertMonitoringUserRole($obj)
}
function addOperatorRoles {
write-host "adding Operator Roles"
$operatorroles.getEnumerator() | foreach -process { addOperatorRole $_.Name}
}