Set CimInstance - PowerShell


Overview

The Set-CimInstance cmdlet modifies the properties of an existing Common Information Model (CIM) instance. It updates the specified properties while maintaining the object’s identity. This cmdlet is useful for managing and updating CIM instances, such as those representing hardware components or configuration settings.

Syntax

Set-CimInstance [-Namespace <string>] [-Property <string[]>] -Value <object> [-ComputerName <string>] [-Authentication <PsAuthentication>] [-Force] [-Verbose] [-Debug] [-OutVariable <string>] [-ErrorAction <ActionPreference>] [-ErrorVariable <string>]

Options/Flags

  • Namespace: Specifies the namespace within which the CIM instance resides. Defaults to the “root/cimv2” namespace.
  • Property: The name of the property or properties to be modified. Specify multiple properties with an array of strings.
  • Value: The new value to set for the specified properties. Supports a single value or hashtable for multiple values.
  • ComputerName: The name of the remote computer on which the command should be executed.
  • Authentication: Specifies the authentication method to be used when connecting to the remote computer. Default authentication mechanisms are utilized if this option is omitted.
  • Force: Suppresses confirmation prompts when overwriting existing values.
  • Verbose: Provides detailed output for troubleshooting purposes.
  • Debug: Outputs diagnostic information for debugging purposes.
  • OutVariable: Stores the output of the command in the specified variable for later use.
  • ErrorAction: Specifies the action to be taken when an error occurs. Default value is “Stop”.
  • ErrorVariable: Stores error output in the specified variable for later use.

Examples

Example 1: Modifying a single property

Set-CimInstance -Namespace "root/cimv2" -Property "Name" -Value "UpdatedName"

Example 2: Modifying multiple properties

Set-CimInstance -Namespace "root/cimv2" -Property @( "Name", "Description" ) -Value @{
    Name = "UpdatedName"
    Description = "Updated Description"
}

Example 3: Modifying a property on a remote computer

Set-CimInstance -ComputerName "RemoteComputer" -Namespace "root/cimv2" -Property "Name" -Value "UpdatedName"

Common Issues

  • Access denied errors: Ensure that you have sufficient permissions to modify the specified CIM instance.
  • Invalid property names: Verify that the property names specified in the -Property parameter are correct.
  • Value type mismatch: Check that the value provided for the -Value parameter matches the expected data type of the property being modified.

Integration

Set-CimInstance can be integrated with other PowerShell cmdlets to automate complex tasks. For example, it can be used in conjunction with Get-CimInstance to retrieve an instance, modify its properties using Set-CimInstance, and then save the changes using Invoke-CimMethod.

  • Get-CimInstance
  • New-CimInstance
  • Invoke-CimMethod