I have to run a script on Computer A that will connect to Computer B
and check if a certain COM+ application is running. If the COM+ is
running, I need to shut it down. How does PowerShell go about
interacting with COM+?
$targetComputer = "irealm"
$targetApplication = "COM+ QC Dead Letter Queue Listener"
$comAdmin = New-Object -comobject COMAdmin.COMAdminCatalog
$apps = $comAdmin.GetCollection("Applications")
$apps.Populate()
$app = $apps | Where-Object { $_.Name -eq $targetApplication }
$insts = $apps.GetCollection("ApplicationInstances",$app.Key)
$insts.Populate()
$isRunning = $insts.Count -gt 0
if ($isRunning) { Write-Output Running } else { Write-Output "Not Running" }
if ($isRunning) { $comAdmin.ShutDownApplication($app.Key) }
Also note that you don't need to check if application is running if you
just need to shut it down. ShutdownApplication method won't return a
error if an application is already shutdown.
//Andrew
$comAdmin.Connect($targetComputer)
right after
$comAdmin = New-Object -comobject COMAdmin.COMAdminCatalog
//Andrew
And I did get to use that IsRunning check to make sure the app started
up later on. :)