Answered by:
Set-CimInstance - A general error co

Question
-
I'm having trouble modifying an existing instance - specifically clearing the value.
Leveraging the PowerShell code from this article: https://docs.microsoft.com/en-us/windows/configuration/kiosk-mdm-bridge, I have successfully applied an XML configuration to the class MDM_AssignedAccess under root\cimv2\mdm\dmmap. Everything works as expected.
I now want to clear the XML configuration and revert my changes. The code in this article applies the XML:
$nameSpaceName="root\cimv2\mdm\dmmap" $className="MDM_AssignedAccess" $obj = Get-CimInstance -Namespace $namespaceName -ClassName $className Add-Type -AssemblyName System.Web $obj.Configuration = [System.Web.HttpUtility]::HtmlEncode(@" <XML> "@) Set-CimInstance -CimInstance $obj
This article (under # Modify existing instance) indicates I can assign a new value and update the instance just I did initially.
However, when I attempt the following I get a generic error.
$nameSpaceName="root\cimv2\mdm\dmmap" $className="MDM_AssignedAccess" $obj = Get-CimInstance -Namespace $namespaceName -ClassName $className $obj.Configuration = '' Set-CimInstance -CimInstance $obj
The returned error is: Set-CimInstance : A general error occurred that is not covered by a more specific error code.
How do I go about clearing the Configuration property in this scenario?
- Edited by LearnNewThings Thursday, January 23, 2020 10:26 PM
Thursday, January 23, 2020 10:25 PM
Answers
-
Ended up being simpler than that.
$obj.Configuration = $null Set-CimInstance -CimInstance $obj
This did the job.
- Marked as answer by LearnNewThings Monday, January 27, 2020 3:48 PM
- Edited by LearnNewThings Monday, January 27, 2020 4:25 PM
Monday, January 27, 2020 3:47 PM
All replies
-
You can't clear the configuration you can only delete the instance you have created.
Retrieve the instance and delete it.
Get-CimInstance -Namespace $namespaceName -ClassName $className | Remove-CimInstance
\_(ツ)_/
- Edited by jrv Thursday, January 23, 2020 10:59 PM
Thursday, January 23, 2020 10:57 PM -
I tried that as well. Doesn't look like that is a supported option.
Remove-CimInstance : The requested operation is not supported.
I may be wrong, but the instance is also already present on a vanilla build (before any changes). Configuration is simply blank.
Configuration : InstanceID : AssignedAccess KioskModeApp : ParentID : ./Vendor/MSFT ShellLauncher : PSComputerName : CimClass : root/cimv2/mdm/dmmap:MDM_AssignedAccess CimInstanceProperties : {Configuration, InstanceID, KioskModeApp, ParentID...} CimSystemProperties : Microsoft.Management.Infrastructure.CimSystemProperties
I've used a PPKG to apply this XML and it somehow writes the Configuration and then clears it when I remove the PPKG. Just not sure what its doing under the hood.
- Edited by LearnNewThings Thursday, January 23, 2020 11:31 PM
Thursday, January 23, 2020 11:28 PM -
If you have more than one instance then you have to choose the instance.
\_(ツ)_/
Thursday, January 23, 2020 11:35 PM -
There is only a single instance.Friday, January 24, 2020 9:38 PM
-
Did you follow the instructions in the article you posted? That shows you the direct Net method of creating and deleting an instance.
\_(ツ)_/
Friday, January 24, 2020 9:43 PM -
Ended up being simpler than that.
$obj.Configuration = $null Set-CimInstance -CimInstance $obj
This did the job.
- Marked as answer by LearnNewThings Monday, January 27, 2020 3:48 PM
- Edited by LearnNewThings Monday, January 27, 2020 4:25 PM
Monday, January 27, 2020 3:47 PM