PowerShell Logo Small

Set-CimInstance



This is the built-in help made by Microsoft for the command 'Set-CimInstance', in PowerShell version 5 - as retrieved from Windows version 'Microsoft Windows Server 2012 R2 Standard' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

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

SYNTAX


Set-CimInstance [-InputObject] <CimInstance> [-ComputerName <String[]>] [-OperationTimeoutSec <UInt32>] [-PassThru] [-Property <IDictionary>] [-ResourceUri <Uri>] [-Confirm]
[-WhatIf] [<CommonParameters>]
Set-CimInstance [-Query] <String> [-Namespace <String>] [-OperationTimeoutSec <UInt32>] [-PassThru] [-QueryDialect <String>] -CimSession <CimSession[]> -Property
<IDictionary> [-Confirm] [-WhatIf] [<CommonParameters>]
Set-CimInstance [-InputObject] <CimInstance> [-OperationTimeoutSec <UInt32>] [-PassThru] [-Property <IDictionary>] [-ResourceUri <Uri>] -CimSession <CimSession[]> [-Confirm]
[-WhatIf] [<CommonParameters>]
Set-CimInstance [-Query] <String> [-ComputerName <String[]>] [-Namespace <String>] [-OperationTimeoutSec <UInt32>] [-PassThru] [-QueryDialect <String>] -Property
<IDictionary> [-Confirm] [-WhatIf] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


The Set-CimInstance cmdlet modifies a CIM instance on a CIM server.


If the InputObject parameter is not specified, the cmdlet works in one of the following ways:

--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 InputObject parameter is specified, the cmdlet works in one of the following ways:

--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 the either the CimSession parameter value or ComputerName
parameter value. Note: This is not very common.



<

RELATED LINKS

Get-CimInstance
New-CimInstance
Remove-CimInstance

REMARKS

<

Examples


Example 1: Set the CIM instance

PS C:\>Set-CimInstance -Query 'Select * from Win32_Environment where name LIKE "testvar%"' -Property @{VariableValue="abcd"}



This command sets the value of the VariableValue property to abcd using the Query parameter. You can modify instances matching a Windows Management Instrumentation Query
Language (WQL) query.






Example 2: Set the CIM instance property using pipeline

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



This command retrieves the CIM instance object filtered by the Query parameter using the Get-CimInstance cmdlet, and then passes the objects to the Set-CimInstance cmdlet,
which modifies the value of VariableValue property to abcd.






Example 3: Set the CIM instance property using input object

PS C:\>$x = Get-CimInstance -Query 'Select * from Win32_Environment where Name="testvar"'



PS C:\>Set-CimInstance -InputObject $x -Property @{VariableValue="somevalue"} -PassThru



This set of commands retrieves the CIM instance objects filtered by the Query parameter in to a variable ($x) using Get-CimInstance, and then passes the contents of the
variable to the Set-CimInstance cmdlet. Set-CimInstance then modifies the VariableValue property to somevalue. Because the Passthru parameter is used, this set of commands
returns a modified CIM instance object.






Example 4: Set the CIM instance property

PS C:\>$x = Get-CimInstance -Query 'Select * from Win32_Environment where name="testvar"'



PS C:\>$x.VariableValue = "Change"



PS C:\>Set-CimInstance -CimInstance $x -PassThru



This set of commands retrieves the CIM instance object that is specified in the Query parameter into a variable ($x) using the Get-CimInstance cmdlet, and changes the
VariableValue property value of the object to change. The CIM instance object is then saved using the Set-CimInstance cmdlet. Because the Passthru parameter is used, this
set of commands returns a modified CIM instance object.






Example 5: Show the list of CIM instances to modify using WhatIf

PS C:\>Set-CimInstance -Query 'Select * from Win32_Environment where name LIKE "testvar%"' -Property @{VariableValue="abcd"} -WhatIf



This command uses the common parameter WhatIf to specify that the modification should not be done, but only output what would happen if it were done.






Example 6: Set the CIM instance after confirmation from the user

PS C:\>Set-CimInstance -Query 'Select * from Win32_Environment where name LIKE "testvar%"' -Property @{VariableValue="abcd"} -Confirm



This command uses the common parameter Confirm to specify that the modification should be done only after confirmation from the user.






Example 7: Set the created CIM instance

PS C:\>$x = New-CimInstance -ClassName Win32_Environment -Property @{Name="testvar";UserName="domain\user"} -Keys Name,UserName -ClientOnly



PS C:\>Set-CimInstance -CimInstance $x -Property @{VariableValue="somevalue"} -PassThru



This set of commands creates a CIM instance with the specified properties using the New-CimInstance cmdlet, and retrieves its contents in to a variable ($x). The variable is
then passed to the Set-CimInstance cmdlet, which modifies the value of VariableValue property to somevalue. Because the Passthru parameter is used, this set of commands
returns a modified CIM instance object.