Set-CIMInstance (PowerShell 3.0+ )

Modify a CIM instance on a CIM server by calling the ModifyInstance method of the CIM class.

The Common Information Model (CIM) is the DMTF standard [DSP0004] for describing the structure and behavior of managed resources such as storage, network, or software components.

Syntax
      Set-CimInstance -Query String
         [ -ComputerName String[] | -CimSession CimSession[] ]
            -Property IDictionary
               [-Namespace String] [-QueryDialect String] [-PassThru] 
                  [-OperationTimeoutSec UInt32] [-Confirm] [-WhatIf] [CommonParameters]

      Get-CimInstance [-InputObject] CimInstance
         [ -ComputerName String[] | -CimSession CimSession[] ]
            [-Property IDictionary] [-ResourceUri Uri] [-PassThru]
               [-OperationTimeoutSec UInt32] [-Confirm] [-WhatIf] [CommonParameters]

Key
   -CimSession CimSession[]
       Run the cmdlets on a remote computer. Enter a variable that contains the CIM session or a command 
       that creates or gets the CIM session, such as the New-CimSession or Get-CimSession cmdlets. For more 
       information, see about_CimSessions.

   -ComputerName String[]
       The computer on which you want to run the CIM operation. You can specify a fully qualified domain name 
       (FQDN), or a NetBIOS name.

       If you specify this parameter, the cmdlet creates a temporary session to the specified computer using the 
       WsMan protocol.If you do not specify this parameter, the cmdlet performs the operation on the local computer
       using Component Object Model (COM).

       If multiple operations are being performed on the same computer, using a CIM session gives better performance.

   -InputObject CimInstance
       Specifies a CIM instance object to use as input.

       -- If neither the -ComputerName parameter nor the -CimSession parameter is specified, then this cmdlet uses the CIM
          session or computer name from the input object.

       -- If the either the -ComputerName parameter or the -CimSession parameter is specified, then this cmdlet uses
          either the -CimSession parameter value or -ComputerName parameter value.  Note: This is not very common.

   -Namespace String
       Specifies the namespace of CIM class.

       The default namespace is root/cimv2. 
       NOTE: You can use tab completion to browse the list of namespaces, because wps_2 gets a list of namespaces 
       from the local WMI server to provide the list of namespaces.

   -OperationTimeoutSec UInt32
       Specifies the amount of time that the cmdlet waits for a response from the computer.

       By default, the value of this parameter is 0, which means that the cmdlet uses the default timeout value for 
       the server.

       If the OperationTimeoutSec parameter is set to a value less than the robust connection retry timeout of 3 
       minutes, network failures that last more than the value of the OperationTimeoutSec parameter are not 
       recoverable, because the operation on the server times out before the client can reconnect.

   -PassThru
       Passthru the pipeline.

   -Property IDictionary[]
       Specifies the properties of the CIM instance as a hash table (using name-value pairs). Only the properties
       specified using this parameter are changed. Other properties of the CIM instance are not changed.

   -Query String
       Specifies a query to run on the CIM server to retrieve CIM instances on which to run the cmdlet.
       You can specify the query dialect using the -QueryDialect parameter.

       --If neither the -ComputerName parameter nor the -CimSession parameter is specified, then this cmdlet works on
         local Windows Management Instrumentation (WMI) using a Component Object Model (COM) session.

       --If either the -ComputerName parameter or the -CimSession parameter is specified, then this cmdlet works against
         the CIM server specified by either the -ComputerName parameter or the -CimSession parameter.

       If the value specified contains double quotes (“), single quotes (‘), or a backslash (\), you must escape 
       those characters by prefixing them with the backslash (\) character. If the value specified uses the WQL LIKE 
       operator, then you must escape the following characters by enclosing them in square brackets ([]): percent 
       (%), underscore (_), or opening square bracket ([).

       You cannot use a metadata query to retrieve a list of classes or an event query. To retrieve a list of 
       classes, use the Get-CimClass cmdlet. To retrieve an event query, use the Register-CimIndicationEvent cmdlet.

       You can specify the query dialect using the -QueryDialect parameter.

   -QueryDialect String
       Specifies the query language used for the Query parameter.

       psdx_paramvalues WQL or CQL.

       The default value is WQL.

   -ResourceUri Uri
       Specifies the resource uniform resource identifier (URI) of the resource class or instance. The URI is used to 
       identify a specific type of resource, such as disks or processes, on a computer.

       A URI consists of a prefix and a path to a resource. For example: 

       http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/Win32_LogicalDisk
       http://intel.com/wbem/wscim/1/amt-schema/1/AMT_GeneralSettings
       
       By default, if you do not specify this parameter, the DMTF standard resource URI 
       http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/ is used and the class name is appended to it.
       
       ResourceURI can only be used with CIM sessions created using the WSMan protocol, or when specifying the 
       ComputerName parameter, which creates a CIM session using WSMan. If you specify this parameter without 
       specifying the ComputerName parameter, or if you specify a CIM session created using DCOM protocol, you will 
       get an error, because the DCOM protocol does not support the ResourceURI parameter.

       If both the -ResourceUri parameter and the -Filter parameter are specified, the -Filter parameter is ignored.

   -Confirm
       Prompt for confirmation before executing the command.

   -WhatIf
       Describe what would happen if you executed the command without actually executing it.

   CommonParameters:
       -Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable,
       -OutBuffer, -PipelineVariable -OutVariable.

Standard Alias for Set-CIMInstance: scim

The results of Get-CimInstance can be piped into Set-CimInstance

Examples

Read the value of the OS Environment Variable (a <System> variable) :

PS C:\> Get-CimInstance -Query 'Select * from Win32_Environment where name = "OS"'
 Name   VariableValue
 ----   -------------
 OS     Windows_NT 

Change the value of the OS Environment Variable (requires elevation):

PS C:\> Get-CimInstance -Query 'Select * from Win32_Environment where name = "OS"' | Set-CimInstance -Property @{VariableValue="Windows_95"}

The same change can be made, passing a variable ($x) using -InputObject:

PS> $x = Get-CimInstance -Query 'Select * from Win32_Environment where Name="OS"'
PS> Set-CimInstance -InputObject $x -Property @{VariableValue="Windows_95"} -PassThru

Because the -Passthru parameter is used, the above set of commands returns a modified CIM instance object.

A third option is to modify the object before passing it to Set-CimInstance:

PS C:\> $x = Get-CimInstance -Query 'Select * from Win32_Environment where name="OS"'
PS C:\> $x.VariableValue = "Windows_95"
PS C:\> Set-CimInstance -CimInstance $x -PassThru

Because the -Passthru parameter is used, the above set of commands returns a modified CIM instance object.

“If you feel safe in the area you’re working in, you’re not working in the right area. Always go a little further into the water than you feel you’re capable of being in. Go a little bit out of your depth. And when you don’t feel that your feet are quite touching the bottom, you’re just about in the right place to do something exciting.” ~ David Bowie

Related PowerShell Commands:

Get-CimInstance - Get a managed resource (storage, network, software etc).
Invoke-CimMethod - Invoke a method of a CIM class or CIM instance.
New-CimInstance - Create a new instance of a class.
Remove-CimInstance - Remove a CIM instance from a computer.


Copyright © SS64.com 1999-2019
Some rights reserved