#PSTip Another way to modify WMI instance properties

In the previous tip we showed you how to modify WMI object properties using Get-WmiObject cmdlet and the Put method. Today I want to show you another streamlined way to do the same using the Set-WmiInstance cmdlet.

The Set-WmiInstance cmdlet creates or updates an instance of an existing WMI class and writes the updates back to the WMI repository. So, if we wanted to modify the volume name of drive D:

Get-WmiObject -Class Win32_LogicalDisk -Filter "DeviceID='D:'" |
Set-WmiInstance -Arguments @{VolumeName = "Data"}

The Arguments parameter accepts a hashtable of name-value pair, property names, and the new values we want to set. To update multiple properties, delimit them with a semicolon @{Property1=’Value1′; Property=’Value2′}

Note: You must have administrative rights to update the properties and the console must be run elevated.

Filed in: Columns, Tips and Tricks Tags: , ,

3 Responses to "#PSTip Another way to modify WMI instance properties"

  1. queens76dc says:

    I’m attempting the following:

    Get-WmiObject -Namespace root\dcim\sysman -Class DCIM_BIOSEnumeration -Filter “AttributeName = ‘Auto On'” | Set-WmiInstance -Arguments @{CurrentValue = “1”}

    But I get this error:

    Set-WmiInstance : Unable to cast object of type ‘System.String’ to type ‘System.Array’.

    Do you know what I’m doing wrong?


  2. Shay Levy says:

    Try to pass the value (if it’s an integer) without the quotes.
    If it doesn’t help try to cast it to array:

    @{CurrentValue = @(1) }

  3. Ramya says:


    can you please help me in creating custom properties for a wmi class. I used the below code to create custom properties. After running the script, i see the properties in wmi explorer but when running a cmdlet to display the properties it doesnot .As a result i am not able to set values to these properties.

    [wmiclass]$WMI_Class = Get-WmiObject -Class $ClassName -Namespace $NameSpace -list

    $WMI_Class.Properties.add($PropertyName, $PropertyValue)

Leave a Reply

Submit Comment

© 2018 PowerShell Magazine. All rights reserved. XHTML / CSS Valid.
Proudly designed by Theme Junkie.
%d bloggers like this: