Forum Discussion
Mike_Elliott
Nov 17, 2020Copper Contributor
Microsoft Monitoring Agent - powershell script problem
Morning all. I've created a short script to help me modify the configuration of Microsoft Monitoring Agent installed on some servers. The script seems to work well with one exception (pardon the pun)...
Mike_Elliott
Copper Contributor
Thijs Lecomte Yes please, I'll try what you have and incorporate if possible.
Thijs Lecomte
Nov 19, 2020Bronze Contributor
$multipleWorkspaces = $false
$mma = New-Object -ComObject 'AgentConfigManager.MgmtSvcCfg'
$workspaces = $mma.GetCloudWorkspaces()
if($workspaces[1]){
$multipleWorkspaces = $true
Write-Log -Message "Multiple workspaces configured" -Source $deployAppScriptFriendlyName
}
if($multipleWorkspaces){
$mma.RemoveCloudWorkspace($WorkspaceId)
$mma.ReloadConfiguration()
Write-Log -Message "Removed workspace $workspaceId" -Source $deployAppScriptFriendlyName
}
else{
$appInstalled = Get-InstalledApplication -Name "Microsoft Monitoring Agent"
$appInstalledCount = $(($appInstalled | Measure-Object).Count)
Write-Log -Message "Detected $appInstalledCount instances of $appName" -Severity 1 -Source $deployAppScriptFriendlyName
foreach ($appInstallation in $appInstalled) {
Write-Log -Message "Processing $($appInstallation.DisplayName) $($appInstallation.DisplayVersion)" -Severity 1 -Source $deployAppScriptFriendlyName
Write-Log -Message "UninstallString: $($appInstallation.UninstallString)" -Severity 1 -Source $deployAppScriptFriendlyName
# If the uninstallstring has quotes, you need to remove them
$uninstallString = $appInstallation.UninstallString.Replace('"', "")
$uninstallString = $appInstallation.UninstallString.Replace('MsiExec.exe /I', "")
Write-Log -Message "Updated UninstallString: $($uninstallString)" -Severity 1 -Source $deployAppScriptFriendlyName
Execute-MSI -Action Uninstall -Path $uninstallString
Write-Log -Message "Exit Code: $($execProcess.ExitCode)" -Severity 1 -Source $deployAppScriptFriendlyName
}
Write-Log -Message "Uninstalled MMA" -Source $deployAppScriptFriendlyName
}
This is the script. Know that is uses PSADT so some functions will not work out of the box PS