Nov 17 2020 02:01 AM - edited Nov 19 2020 04:07 AM
PS C:\test> .\MMA_modify_workspace.ps1 -action remove 3109a0e6-520f-4da5-9c0e-xxxxxxxxxxxx
The wait operation timed out. (Exception from HRESULT: 0x80070102)
At C:\test\MMA_modify_workspace.ps1:43 char:5
+ $mma.ReloadConfiguration()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped:
) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
Workspace 3109a0e6-520f-4da5-9c0e-xxxxxxxxxxxx removed.
Nov 18 2020 11:51 AM
Nov 18 2020 12:36 PM
@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.
Nov 19 2020 10:44 AM
Nov 19 2020 10:47 AM
@Thijs Lecomte Yes please, I'll try what you have and incorporate if possible.
Nov 19 2020 10:52 AM
$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