When working with COM+ components in Windows environments, PowerShell provides several powerful approaches through both native cmdlets and COM object access. The COM+ Admin library (comadmin.dll) exposes the necessary interfaces we can leverage programmatically.
To verify if a COM+ application exists:
$comAdmin = New-Object -comobject COMAdmin.COMAdminCatalog
$apps = $comAdmin.GetCollection("Applications")
$apps.Populate()
$targetApp = "MyCOMApp"
$appExists = $apps | Where-Object { $_.Name -eq $targetApp } | Select-Object -First 1
if ($appExists) {
Write-Host "$targetApp is registered"
} else {
Write-Host "$targetApp not found"
}
Starting and stopping applications requires accessing the application's IsEnabled property:
# Stop application
$app = $apps | Where-Object { $_.Name -eq $targetApp } | Select-Object -First 1
$app.Value("IsEnabled") = $false
$apps.SaveChanges()
# Start application
$app.Value("IsEnabled") = $true
$apps.SaveChanges()
For registration operations, we use the InstallApplication and ShutdownApplication methods:
# Install from MSI
$comAdmin.InstallApplication("C:\path\to\application.msi")
# Uninstall by name
$comAdmin.ShutdownApplication($targetApp)
While PowerShell doesn't include native COM+ cmdlets, we can create reusable functions:
function Get-COMApplication {
param([string]$Name)
$comAdmin = New-Object -comobject COMAdmin.COMAdminCatalog
$apps = $comAdmin.GetCollection("Applications")
$apps.Populate()
if ($Name) {
$apps | Where-Object { $_.Name -eq $Name }
} else {
$apps
}
}
function Start-COMApplication {
param([string]$Name)
$app = Get-COMApplication -Name $Name
$app.Value("IsEnabled") = $true
$app.Collection.SaveChanges()
}
- Always run PowerShell as Administrator when modifying COM+ settings
- Changes made programmatically may require component restarts
- For production environments, consider implementing error handling and logging
- The COMAdminCatalog object supports many other useful methods like GetApplications, ExportApplication, and ImportComponent
COM+ (Component Services) administration through PowerShell is often needed for enterprise application management. While PowerShell doesn't include native COM+ cmdlets, we can leverage COM automation through the COMAdmin.COMAdminCatalog object to perform all necessary operations.
First, let's create a COMAdminCatalog object instance:
$comAdmin = New-Object -ComObject "COMAdmin.COMAdminCatalog"
$applications = $comAdmin.GetCollection("Applications")
$applications.Populate()
To check if a COM+ application is installed:
function Test-COMPlusApplication {
param([string]$appName)
$comAdmin = New-Object -ComObject "COMAdmin.COMAdminCatalog"
$apps = $comAdmin.GetCollection("Applications")
$apps.Populate()
return ($apps | Where-Object { $_.Name -eq $appName }).Count -gt 0
}
# Usage:
Test-COMPlusApplication -appName "MyCOMApp"
Control COM+ application state with these functions:
function Start-COMPlusApplication {
param([string]$appName)
$comAdmin = New-Object -ComObject "COMAdmin.COMAdminCatalog"
$apps = $comAdmin.GetCollection("Applications")
$apps.Populate()
$app = $apps | Where-Object { $_.Name -eq $appName }
if ($app) {
$app.Value("IsEnabled") = $true
$apps.SaveChanges()
}
}
function Stop-COMPlusApplication {
param([string]$appName)
$comAdmin = New-Object -ComObject "COMAdmin.COMAdminCatalog"
$apps = $comAdmin.GetCollection("Applications")
$apps.Populate()
$app = $apps | Where-Object { $_.Name -eq $appName }
if ($app) {
$app.Value("IsEnabled") = $false
$apps.SaveChanges()
}
}
For application registration and removal:
function Install-COMPlusApplication {
param(
[string]$appName,
[string]$dllPath,
[string]$appDescription = ""
)
$comAdmin = New-Object -ComObject "COMAdmin.COMAdminCatalog"
# Create new application
$apps = $comAdmin.GetCollection("Applications")
$apps.Populate()
$newApp = $apps.Add()
$newApp.Value("Name") = $appName
$newApp.Value("Description") = $appDescription
$apps.SaveChanges()
# Install components
$appKey = ($apps | Where-Object { $_.Name -eq $appName }).Key
$components = $comAdmin.GetCollection("Components", $appKey)
$components.Populate()
$comAdmin.InstallComponent($appKey, $dllPath, "", "")
$components.SaveChanges()
}
function Uninstall-COMPlusApplication {
param([string]$appName)
$comAdmin = New-Object -ComObject "COMAdmin.COMAdminCatalog"
$apps = $comAdmin.GetCollection("Applications")
$apps.Populate()
$app = $apps | Where-Object { $_.Name -eq $appName }
if ($app) {
$apps.Remove($app.Index)
$apps.SaveChanges()
}
}
For more complex scenarios, you can extend these basic functions:
function Get-COMPlusApplicationDetails {
param([string]$appName)
$comAdmin = New-Object -ComObject "COMAdmin.COMAdminCatalog"
$apps = $comAdmin.GetCollection("Applications")
$apps.Populate()
$app = $apps | Where-Object { $_.Name -eq $appName }
if ($app) {
$props = @{}
foreach ($property in $app.ValueNames) {
$props[$property] = $app.Value($property)
}
return [PSCustomObject]$props
}
}
function Set-COMPlusApplicationProperty {
param(
[string]$appName,
[string]$propertyName,
[object]$propertyValue
)
$comAdmin = New-Object -ComObject "COMAdmin.COMAdminCatalog"
$apps = $comAdmin.GetCollection("Applications")
$apps.Populate()
$app = $apps | Where-Object { $_.Name -eq $appName }
if ($app) {
$app.Value($propertyName) = $propertyValue
$apps.SaveChanges()
}
}