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
Nov 18, 2020Copper Contributor
Thijs Lecomte Thanks for getting back. So it seems so far to be confined to a couple of hosts, both of these are VMs on VMWare workstation. I've only tested on a few servers though so not a big sample so far. Servers are 2019, MMA agent is 10.20.18053.0 so the latest I beleive.
The issue only occurs when I attempt to remove a workspaceID. In my tests the workspace ID I'm removing is the last one on the agent.
Thijs Lecomte
Nov 19, 2020Bronze Contributor
Ahn that is possible.
I have a script that checks if it's the last workspace, it just removes the workspaces. Is this something you could implement?
I can share it if you want
I have a script that checks if it's the last workspace, it just removes the workspaces. Is this something you could implement?
I can share it if you want
- Mike_ElliottNov 19, 2020Copper Contributor
Thijs Lecomte Yes please, I'll try what you have and incorporate if possible.
- Thijs LecomteNov 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