SlopTonio
SlopTonio

Reputation: 1105

Powershell reset all com+

I want to reset all com+ on all the servers I am looping through. This is what I have so far

$servers = Get-Content "d:\scripts\servers.txt"
foreach ($servername in $servers)
{

$comAdmin = New-Object -comobject COMAdmin.COMAdminCatalog
$comAdmin.Connect($servername)
$comAdmin.ShutdownApplication(com+ app name goes here)

}

I want to shutdown all complus components without having to specify the name

Upvotes: 0

Views: 1800

Answers (1)

SomeShinyObject
SomeShinyObject

Reputation: 7801

Use COMAdmin:

$sb = {
    $admin = New-Object -Com ("COMAdmin.COMAdminCatalog")
    $apps = $admin.GetCollection("Applications")
    $apps.Populate()
    $apps | % {
        $component = $apps.GetCollection("Components", $_.Key)
        $component.Populate()
        $component | % {
            $admin.ShutdownApplication("$_.Name")
        } 
    }
}

$servers | % {Invoke-Command -ComputerName $_ -ScriptBlock $sb}

More info here. I just compiled the logic of all of it.

Upvotes: 2

Related Questions