Set-SCGuestInfo

Sets the value associated with a key for a key/value pair in a guest operating system.

Description

The Set-SCGuestInfo cmdlet sets the value associated with a key for a key/value pair in a guest operating system.

For more information about Set-SCGuestInfo, type: "Get-Help Set-SCGuestInfo -online".

Parameters

KvpMap

Required? true
Accept Pipeline Input? false
Position? named
Specifies a hashtable of key/value pairs (KVPs) corresponding to the KVP values exposed by Hyper-V.

JobVariable

Required? false
Accept Pipeline Input? false
Position? named
Specifies that job progress is tracked and stored in the variable named by this parameter. 

PROTipID

Required? false
Accept Pipeline Input? false
Position? named
Specifies the ID of the PRO tip that triggered this action. This allows for auditing of PRO tips.

RunAsynchronously

Required? false
Accept Pipeline Input? false
Position? named
Indicates that the job runs asynchronously so that control returns to the command shell immediately. 

VM

Required? false
Accept Pipeline Input? false
Position? named
Specifies a virtual machine object.

Value

Required? false
Accept Pipeline Input? false
Position? 2
Specifies a string used to attribute an object or property.

Key

Required? true
Accept Pipeline Input? false
Position? 1
Specifies the key in a key/value pair (KVP).

JobVariable

Required? false
Accept Pipeline Input? false
Position? named
Specifies that job progress is tracked and stored in the variable named by this parameter. 

PROTipID

Required? false
Accept Pipeline Input? false
Position? named
Specifies the ID of the PRO tip that triggered this action. This allows for auditing of PRO tips.

RunAsynchronously

Required? false
Accept Pipeline Input? false
Position? named
Indicates that the job runs asynchronously so that control returns to the command shell immediately. 

VM

Required? false
Accept Pipeline Input? false
Position? named
Specifies a virtual machine object.

Examples

1: Set a single key/value pair.
PS C:\> $VM = Get-SCVirtualMachine "VM01" 
PS C:\> Set-SCGuestInfo -VM $VM -Key Key -Value Value
The first command gets the virtual machine object named VM01 and stores the object in the $VM variable.

The second command sets a key/value pair for VM01.
2: Set a key to a value for a key/value pair.
PS C:\> Get-SCVirtualMachine -Name "VM01" | Set-SCGuestInfo -Key Microsoft.Lab.Isolation.ServerVersion -Value 1.0.1101
This command sets the key to Microsoft.Lab.Isolation.ServerVersion and the value to 1.0.1101 for the virtual machine named VM01. If the key does not exist, it will be created with the specified value. If the key already exists, its value will be overwritten using the value specified in this command.

You can use the Read-SCGuestInfo cmdlet to provide the key and return its corresponding value.
3: Set multiple key/value pairs.
PS C:\> $VM = Get-SCVirtualMachine -Name "Win2k8R2"
PS C:\> $ValuesMap  = @{"Key1" = "avalue1"; "Key2IsEmptyString" = "" ; "Key3" = "value3"}
PS C:\> Set-SCGuestInfo -VM $VM -KvpMap $ValuesMap
PS C:\> Read-SCGuestInfo -VM $VM -KvpMap $ValuesMap | select KvpMap
The first command gets the virtual machine object named Win2k8R2 and stores the object in the $VM variable.

The second command creates a hashtable named $ValuesMap that contains the corresponding keys and values for the key/value pairs. Values can be set to a string, an empty string, or $null. Setting a value to $null deletes the key.

The third command sets the key/value pairs for the virtual machine named Win2k8R2.

The last command reads back the key/value pairs for the virtual machine named Win2k8R2.
4: Modify a set of values for a set of key/value pairs.
PS C:\> $VM = Get-SCVirtualMachine -Name "Win2k8R2"
PS C:\> $ValuesMap  = @{"Key1" = "avalue1"; "Key2IsEmptyString" = "" ; "Key3" = "value3"}
PS C:\> Set-SCGuestInfo -VM $VM -KvpMap $ValuesMap
PS C:\> Read-SCGuestInfo -VM $VM -KvpMap $ValuesMap | select KvpMap
PS C:\> $ValuesMap  = @{"Key2IsEmptyString" = "KeyIsNoLongerEmpty"}
PS C:\> Set-SCGuestInfo -VM $VM -KvpMap $ValuesMap
PS C:\> $ValuesMap  = @{"Key1" = $null; "Key2IsEmptyString" = $null; "Key3" = $null}
PS C:\> Read-SCGuestInfo -VM $VM -KvpMap $ValuesMap | select KvpMap
The first command gets the virtual machine object named Win2k8R2 and stores the object in the $VM variable.

The second command creates a hashtable named $ValuesMap that contains the corresponding keys and values for the key/value pairs. Values can be set to a string, an empty string, or $null. Setting a value to $null deletes the key.

The third command sets the key/value pairs for the virtual machine named Win2k8R2.

The fourth command reads back the key/value pairs for the virtual machine named Win2k8R2.

The fifth command creates a new hashtable where a specific key is changed to a different value.

The sixth command sets the modified value for the specified key in the hashtable.

The last two commands read back the key/value pairs for the virtual machine named Win2k8R2, including the modifiied value for the key Key2IsEmptyString.
5: Delete a key/value pair using two methods.
PS C:\> $VM = Get-SCVirtualMachine -Name "Win2k8R2"
PS C:\> $ValuesMap  = @{"Key1" = "avalue1"; "Key2" = "avalue2"}
PS C:\> Set-SCGuestInfo -VM $VM -KvpMap $ValuesMap
PS C:\> Read-SCGuestInfo -VM $VM -KvpMap $ValuesMap | select KvpMap
PS C:\> Set-SCGuestInfo -VM $VM -Key Key1 
PS C:\> $KvpsToDelete  = @{"Key2" = $null}
PS C:\> Set-SCGuestInfo -VM $VM -KvpMap $KvpsToDelete  
PS C:\> Read-SCGuestInfo -VM $VM -KvpMap $ValuesMap | select KvpMap
The first command gets the virtual machine object named Win2k8R2 and stores the object in the $VM variable.

The next three commands create two keys and their values and return them to the console for virtual machine Win2k8R2.

The fifth command deletes the key/value pair Key1 by calling Set-SCGuestInfo without specifying the value parameter.

The sixth and seventh commands create a new Hashtable with Null as the value for key Key2. Then, key Key2 is deleted by calling the Set-SCGuestInfo command.

The last command shows that both keys that were initially created are now deleted via two separate methods.
6: Set multiple values where one value is empty.
PS C:\> $VM = Get-SCVirtualMachine -Name "VM01"
PS C:\> $ValuesMap3 = @{"VSLM1" = "value1"; "VLSM2" = "value2" ; "VLSM3" = "value3" ; "VLDM4" = ""}
PS C:\> Set-SCGuestInfo -VM $VM -KVPMap $ValuesMap3
PS C:\> Read-SCGuestInfo -VM $VM -KVPMap $ValuesMap3 | select KVPMap
The first command gets the virtual machine object named VM01 and stores the object in the $VM variable.

The second command creates a hashtable named $ValuesMap3 that contains the corresponding keys and values for the key/value pairs. Values can be set to a string, an empty string, or $null. Setting a value to $null deletes the key.

The third command sets the values for the specified keys in the hashtable.

The last command reads back the key/value pairs for the virtual machine named VM01.
7: Delete one value and set another value to empty.
PS C:\> $VM = Get-SCVirtualMachine -Name "VM01"
PS C:\> $ValuesMap4 = @{"VLSM2" = $null; "VSLM1" = "" }
PS C:\> Set-SCGuestInfo -VM $VM -KVPMap $ValuesMap4
PS C:\> Read-SCGuestInfo -VM $VM -KVPMap $ValuesMap4 | select KVPMap
The first command gets the virtual machine object named VM01 and stores the object in the $VM variable.

The second command creates a hashtable named $ValuesMap4 that contains the corresponding keys and values for the key/value pairs. Values can be set to a string, an empty string, or $null. Setting a value to $null deletes the key.

The third command sets the values for the specified keys in the hashtable.

The fourth command deletes key VLSM2 and sets key VSLM1 to empty by calling the Set-SCGuestInfo command.

The last command reads back the key/value pairs for the virtual machine named VM01.
8: Set one value and delete another value.
PS C:\> $VM = Get-SCVirtualMachine -Name "VM01"
PS C:\> $ValuesMap5 = @{"VSLM1" = "data again"; "VLSM3" = $null }
PS C:\> Set-SCGuestInfo -VM $VM -KVPMap $ValuesMap5
PS C:\> Read-SCGuestInfo -VM $VM -KVPMap $ValuesMap5 | select KVPMap
The first command gets the virtual machine object named VM01 and stores the object in the $VM variable.

The second command creates a hashtable named $ValuesMap5 that contains the corresponding keys and values for the key/value pairs. Values can be set to a string, an empty string, or $null. Setting a value to $null deletes the key.

The fourth command sets key VSLM1 to "data again" and deletes key VLSM3 by calling the Set-SCGuestInfo command.

The last command reads back the key/value pairs for the virtual machine named VM01.
9: Ignore the deletion of keys that do not exist.
PS C:\> $VM = Get-SCVirtualMachine -Name "VM01"
PS C:\> $KeysDoNotExist  = @{"o1ff1" = $null; "o1ff2" = $null; "o1ff3" = $null ; "o1ff4" = $null }
PS C:\> Set-SCGuestInfo -VM $VM -KVPMap $KeysDoNotExist 
PS C:\> Set-SCGuestInfo -VM $VM -Key "o1ff1"
The first command gets the virtual machine object named VM01 and stores the object in the $VM variable.

The second command creates a hashtable named $ValuesMap5 that contains the corresponding keys and values for the key/value pairs. Setting a value to $null deletes the key.

The third command sets the values to $null for the specified keys in the hashtable.

The last command deletes all keys in the hashtable except for key o1ff1 by calling the Set-SCGuestInfo cmdlet.

See Also