teknoglot:

  • Home
  • Home
  • Microsoft
    • Hyper-V
    • OpsMgr 2007
    • SQL 2005
    • SQL 2008
    • Windows XP
    • Windows Vista
    • Windows 2008
  • Linux
    • Fedora 11
    • RedHat ES
    • SLES
    • Ubuntu
  • Code
    • PowerShell
    • VBS
  • Series
    • MP Dev: TG WinAutoSvc
  • Definitions
    • System Center Operations Manager 2007
      • Classes
      • Service Model
      • Singleton
  • Technobabble
Twitter RSS

Bulk disable ACS Forwarders (with wildcards)

Posted on July 7, 2011 by Sam T
2 commentsLeave a comment

Here’s a little something-something for the wicked.

Me and my apprentice is currently decommissioning an entire Management Group with a thousand (-ish) agents. Long story short, we got a new Management Group, migrated all the agents, added a couple of hundreds more, deployed a bunch of gateways and now we are shutting down the old one.

Now, uninstalling the old Management Group from all the agents is a breeze using SCCM and handling the few 20-ish servers that are left is not a biggie either. Shutting down ACS, however, is a different matter.

Although you do configure your forwarders using Operations Manager, removing the management group you were running ACS in does not mean the agents will shut down and disable the AdtAgent service or stop trying to forward audit events to your collector. Now, selecting 10 agents at the time and running the “Disable Audit Collection” task–in case you did not know, there’s a limitation on how many agents you can run a task on in the Operations Console–is not my idea of a jolly good day and since Powershell is a bucket of joy in comparison; here’s a script for you all!

DisableACSForwarders

It is zipped to avoid security alerts, but as with any script found on the internet I implore to to read the code before actually running it.

Anyway, you can use it in a couple of ways.

To run it interactively, just go to the directory where you unpacked it and run it. You will be requested to enter the FQDN of you Root Management Server and a wildcard search for ACS Forwarders.
For example:

PS C:\..\Scripts> .\DisableACSForwarders.ps1
Root Management Server: rms.teknoglot.local
ACS Forwarder name (wildcard): *.teknoglot.local

You can also run it with parameters (for scheduling?) like this:

PS C:\..\Scripts> .\DisableACSForwarders.ps1 rms.teknoglot.local *.teknoglot.local

If you need to run the task with different credentials there’s a switch for that. Just add -UseCredentials to the command and you will be prompted for it.
Like this:

PS C:\..\Scripts> .\DisableACSForwarders.ps1 -UseCredentials

As you might already have realized, the wildcard search does not require actual wildcards. If you only want to disable the ACS forwarder on a single machine, just enter it’s FQDN. As for what wildcards it will accept; anything supported by the powershell -like operator is valid.

[UPDATE!] You might get false failures when running the script on clustered machines because of a bug in the AC Management Pack

 

For the source code, read on!

## Using parameters for RMS and wildcard search
param(
 [string]$rootManagementServer = $(Read-Host -Prompt "Root Management Server"),
 [string]$filterAgents = $(Read-Host -Prompt "ACS Forwarder name (wildcard)"),
 [switch]$UseCredentials
)

## Make sure the $rootManagementServer variable is defined
while (-not $rootManagementServer) {
 Write-Host "`nRoot Management Server MUST be defined!" -ForegroundColor Red
 [string]$rootManagementServer = $(Read-Host -Prompt "Root Management Server")
}

if ($UseCredentials -eq $true) {
 $taskCredentials = Get-Credential
}

$startLocation = Get-Location
$checkPSSnapin = Get-PSSnapin | where {$_.Name -eq "Microsoft.EnterpriseManagement.OperationsManager.Client"}
if ($checkPSSnapin -eq $null) {
 Add-PSSnapin "Microsoft.EnterpriseManagement.OperationsManager.Client"
}
$result = Set-Location "OperationsManagerMonitoring::"
$result = New-ManagementGroupConnection -ConnectionString:$rootManagementServer
$result = Set-Location $rootManagementServer

$acsForwarderClass = Get-MonitoringClass -Name "Microsoft.SystemCenter.ACS.Forwarder"
$agentNames = Get-MonitoringObject -monitoringclass:$acsForwarderClass | where {$_.Path -like $filterAgents} | Select Path
$successfulTasks = @()
$skippedTasks = @()
$failedTasks = @()

$monitoringClass = Get-MonitoringClass -Name "Microsoft.SystemCenter.Agent"
if ($agentNames -ne $null) {
 Write-Host "`nFound"$agentNames.Count"ACS forwarders with wildcard $filterAgents"
 Write-Host "`n`nWaiting for 5 seconds to give you a chance to abort!`n"
 Start-Sleep -Seconds 5
 Write-Host "Time's UP!`n`n"
 $agentNames | ForEach-Object {
 $agentName = $_.Path
 Write-Host "Disabling Audit Collection on" $agentName
 $monitoringObject = Get-MonitoringObject -monitoringclass:$monitoringClass | where {$_.DisplayName -like $agentName}
 $agentTask = $monitoringObject | Get-Task | where {$_.Name -eq "Microsoft.SystemCenter.DisableAuditCollectionService"}
 if ($monitoringObject.IsAvailable -eq $true) {
 if ($credentials -eq $null) {
 $result = Start-Task -Task $agentTask -TargetMonitoringObject $monitoringObject
 } else {
 $result = Start-Task -Task $agentTask -TargetMonitoringObject $monitoringObject -Credential $taskCredentials
 }
 if ($result.Status -eq "Succeeded") {
 Write-Host "Operation Successful!" -ForegroundColor Green
 Write-Host `n
 $successfulTasks += $agentName
 } else {
 Write-Host "Operation failed." -ForegroundColor Red
 Write-Host $result.ErrorMessage
 Write-Host `n
 $failedTasks += $agentName
 }
 } else {
 Write-Host "The agent is unavailable, Skipping!"
 Write-Host `n
 $skippedTasks += $agentName
 }
 }
 Write-Host "Summary"
 Write-Host "`tSuccessful:`t"$successfulTasks.count
 Write-Host "`tFailed:`t`t"$failedTasks.count
 Write-Host "`tSkipped:`t"$skippedTasks.count
} else {
 Write-Host "`nNo ACS Forwarders found using wildcard $filterAgents"
}

Set-Location $startLocation

Enjoy!

Categories: OpsMgr 2007, PowerShell | Tags: ACS, OpsMgr, PowerShell, Script

About Sam T

I am a System Management consultant focusing mainly on System Center Operations Manager, System Center Opalis some Microsoft SQL Server and OP5. Besides doing consulting I am also an MCT and are holding both the official System Center Operations Manager courses at all levels (50028, 50216, 50231) at Cornerstone and Global Knowledge and holds customized classes at customer sites.
View all posts by Sam T→
Notice: This work is licensed under a BY-NC-SA. Permalink: Bulk disable ACS Forwarders (with wildcards)
OpsMgr 2007 R2 Documentation
OpsMgr 2007 Connectivity Map

2 Responses to “Bulk disable ACS Forwarders (with wildcards)”

  1. ChrisAbel says:
    September 26, 2011 at 19:26

    TY sir, you saved me hours of arduous console work!

  2. Sam T says:
    September 28, 2011 at 08:13

    Glad to be of any help!

Leave a Reply Cancel reply

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

*

*


question razz sad evil exclaim smile redface biggrin surprised eek confused cool lol mad twisted rolleyes wink idea arrow neutral cry mrgreen

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • kaTWEET!

    • No public Twitter messages.
  • Categories

    • Code
      • PowerShell
      • VBS
    • Linux
      • Fedora 11
      • RedHat ES
      • SLES
      • Ubuntu
    • Microsoft
      • Hyper-V
      • OpsMgr 2007
      • SQL 2005
      • SQL 2008
      • Windows 2008
      • Windows Vista
      • Windows XP
    • Technobabble
  • Recent Posts

    • Virtual OpenVPN Server at Home
    • OpsMgr 2007 R2 Documentation
    • Bulk disable ACS Forwarders (with wildcards)
    • OpsMgr 2007 Connectivity Map
    • Introduction to TG WinAutoSvc v1
  • Recent Comments

    • Giulise on Installing SQL Reporting Services 2005 on Windows 2008 x64
    • Sam T on Bulk disable ACS Forwarders (with wildcards)
    • ChrisAbel on Bulk disable ACS Forwarders (with wildcards)
    • Sam T on Introduction to TG WinAutoSvc v1
    • mats on Introduction to TG WinAutoSvc v1
© teknoglot:. Proudly Powered by WordPress | Nest Theme by YChong