Set-SCGuestInfo

Set-SCGuestInfo

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

Syntax

Parameter Set: MultipleKvpKeys
Set-SCGuestInfo [-VM] <VM> -KvpMap <Hashtable> [ <CommonParameters>]

Parameter Set: SingleKvpKey
Set-SCGuestInfo [-VM] <VM> [-Key] <String> [[-Value] <String> ] [ <CommonParameters>]

Detailed Description

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

Parameters

-Key<String>

Specifies the key in a key/value pair (KVP).

Aliases

none

Required?

true

Position?

2

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-KvpMap<Hashtable>

Specifies a hashtable of key/value pairs (KVPs) corresponding to the KVP values exposed by Hyper-V.

Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Value<String>

Specifies a string used to attribute an object or property.

Aliases

none

Required?

false

Position?

3

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-VM<VM>

Specifies a virtual machine object.

Aliases

none

Required?

true

Position?

1

Default Value

none

Accept Pipeline Input?

True (ByValue)

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see    about_CommonParameters (https://go.microsoft.com/fwlink/p/?LinkID=113216).

Inputs

The input type is the type of the objects that you can pipe to the cmdlet.

Outputs

The output type is the type of the objects that the cmdlet emits.

  • String

Examples

1: Set a single key/value pair.

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.

PS C:\> $VM = Get-SCVirtualMachine "VM01"
PS C:\> Set-SCGuestInfo -VM $VM -Key Key -Value Value

2: Set a key to a value for a key/value pair.

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.

PS C:\> Get-SCVirtualMachine -Name "VM01" | Set-SCGuestInfo -Key Microsoft.Lab.Isolation.ServerVersion -Value 1.0.1101

3: Set multiple key/value pairs.

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.

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

4: Modify a set of values for a set of key/value pairs.

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.

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

5: Delete a key/value pair using two methods.

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.

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

6: Set multiple values where one value is empty.

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.

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

7: Delete one value and set another value to empty.

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.

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

8: Set one value and delete another value.

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.

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

9: Ignore the deletion of keys that do not exist.

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.

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"

Read-SCGuestInfo