I've seen a few scripts out there on bulk-enabling ACS for just one group of servers in SCOM (OpsMgr 2007.) but nothing seemed to work.
So, I decided to learn powershell so that I could write a better script to do this. Here is what I came up with. About a third of the script is comments that should help you understand
exactly what the script is doing. That way you can have a bit of confidence when running it. Also, if you read the script and the comments a few time hopefully things will start to click
in your mind and you will start to get a better understanding of powershell and SCOM.
To use the script type the script name followed by the FQDN of the RMS the FQDN of the ACS collector, and the display name of the group you want to affect.
Example: acsGroupEnable.ps1 RMS1.yourdomain.int ACS1.yourdomain.int 'your group name' -yes single quotes. Maybe double quotes work too, but I'm too scared to try. ;-)
Here's the script:
param ($rmsServerName,$collectorServerName,$groupName)
#To list all groups by displayName connect to root of management server
#via powershell and run: get-childitem | format-list -property displayname
#Connect to RMS using FQDN
#add-pssnapin "Microsoft.EnterpriseManagement.OperationsManager.Client" #Use this if you aren't on the SCOM Powershell Console.
set-location "OperationsManagerMonitoring::"
new-managementGroupConnection -ConnectionString:$rmsServerName;
set-location $rmsServerName
#Create Health Service Class Instance for later use.
$healthServiceClass = get-monitoringclass -name:Microsoft.SystemCenter.HealthService
#Create a task that enables ACS when invoked
$enableAcsTask = get-task -path \ | where {$_.Name -eq 'Microsoft.SystemCenter.EnableAuditCollectionService'}
#Create override for ACS
$overrides = new-object Hashtable
$overrides.Add("CollectorServer",$collectorServerName)
#Use credentials only if you need to. Otherwise leave commented out.
#$credentials = Get-Credential #use this if you are not logged in with correct OpsMgr account.
#get all computer objects from the group you want to affect and put them into a collection
$colServers = Get-ChildItem (get-childItem | where {$_.displayName -eq $groupName}).PathName;
#for each computer in the collection, connect to that computer's health service object
foreach($varServer in $colServers)
{
$healthServices = $varServer.GetRelatedMonitoringObjects($healthServiceClass)
foreach($hs in $healthServices) #for each server in that class (Only the one server you have connected to.)
{
if ($hs.isAvailable -eq $true) #if the server is currently talking to OpsMgr
{
"Enabling Audit Collection for " + $hs.DisplayName;
#Enable ACS on the computer
Start-Task -task:$enableAcsTask -TargetMonitoringObject:$hs -overrides:$overrides #-credential:$credentials #uncomment the credentials if you need to use alternate credentials.
}
else
{
"Skipping: " + $hs.DisplayName + ". This computer is disconnected from OpsMgr."
}
}
}