New-VIProperty Command | Vmware PowerCLI Reference

New-VIProperty

This cmdlet creates a new extension property on the specified object type. Changes take effect upon the next retrieval of the corresponding objects.

Syntax

New-VIProperty
[ -ObjectType ] < String[] >
[ -ValueFromExtensionProperty ] < String >
-Name < String >
[-Force ]
[-ProgressAction < ActionPreference > ]
[CommonParameters]

Parameters

Required Parameter Name Type Position Features Description
required
ObjectType String[] 1
  • wildcards
Specifies the object types to which you want to append the new property. All PowerCLI object types are supported.
required
ValueFromExtensionProperty String 2
Specifies a string that maps a property of the $this.ExtensionData object. This parameter is case-sensitive.
required
Name String named
Specifies a name for the new extension property. Names are case-sensitive and can include only letters, numbers, and the underscore symbol. The name of a property must start with a letter or underscore.
optional Force SwitchParameter named
Indicates that you want to create the new property even if another property with the same name exists for the specified object type. This parameter is not applicable for core properties of an object type.
optional ProgressAction ActionPreference named
New-VIProperty
[ -ObjectType ] < String[] >
[ -Value ] < ScriptBlock >
-Name < String >
[-BasedOnExtensionProperty < String[] > ]
[-Force ]
[-ProgressAction < ActionPreference > ]
[CommonParameters]

Parameters

Required Parameter Name Type Position Features Description
required
ObjectType String[] 1
  • wildcards
Specifies the object types to which you want to append the new property. All PowerCLI object types are supported.
required
Value ScriptBlock 2
Specifies a script block you want to use to compute the value of the new extended property.
required
Name String named
Specifies a name for the new extension property. Names are case-sensitive and can include only letters, numbers, and the underscore symbol. The name of a property must start with a letter or underscore.
optional BasedOnExtensionProperty String[] named
Specifies a list of strings that maps the properties of the $this.ExtensionData object. Use this parameter to specify which members of ExtensionData are used by the script block provided for the Value parameter. This parameter is case-sensitive.
optional Force SwitchParameter named
Indicates that you want to create the new property even if another property with the same name exists for the specified object type. This parameter is not applicable for core properties of an object type.
optional ProgressAction ActionPreference named

Output

VMware.VimAutomation.ViCore.Types.V1.VIProperty

Examples

Example 1

New-VIProperty -ObjectType VirtualMachine -Name CommittedSpaceMB -Value { $vm = $args[0]; $sum = 0; $vm.ExtensionData.Storage.PerDatastoreUsage | foreach { $sum += $_.Committed} ; $sum = [int]($sum / 1024 / 1024); return $sum }

Get-VM | select Name, CommittedSpaceMB

Creates a script-based property for the VirtualMachine object type that calculates the committed space of a virtual machine.

Example 2

New-VIProperty -ObjectType VirtualMachine -Name CommittedSpaceMB -Value { $vm = $args[0]; $sum = 0; $vm.ExtensionData.Storage.PerDatastoreUsage | foreach { $sum += $_.Committed} ; $sum = [int]($sum / 1024 / 1024); return $sum } -BasedOnExtensionProperty 'Storage.PerDatastoreUsage.Committed' -Force

Get-VM | select Name, CommittedSpaceMB

Creates a property that calculates the committed space of a virtual machine. The cmdlet uses the BasedOnExtensionProperty parameter to specify which ExtensionData member is used by the script block. This mean that during the creation of each virtual machine, only the specified property of extension data - Storage.PerDatastoreUsage.Committed will be filled up.

Example 3

New-VIProperty -ObjectType VirtualMachine -Name CommittedSpace -ValueFromExtensionProperty 'SUM Storage.PerDatastoreUsage.Committed'

Creates a new property that calculates the committed storage based on the property and aggregation function SUM specified by the ValueFromExtensionProperty parameter.

Example 4

New-VIProperty -ObjectType InventoryItem -Name OverallStatus -ValueFromExtensionProperty 'OverallStatus'

Get-VM | select Name, OverallStatus

Get-VMHost | select Name, OverallStatus

Creates a new property based on the OverallStatus property for all inventory types.

Example 5

New-VIProperty -ObjectType VIObjectCore -Value { if ( $args[0].UId -match "/VIserver=[\w]+@(.*):.*" ) { $matches[1] } else { " } } -Name VIServerName

Get-Inventory | select Name, VIServerName

Creates a script-based property to VIObjectCore that parses the UId property and extracts the name of the server to which a given object belongs.

Related Commands

VIProperty

This cmdlet retrieves extended object properties.

This cmdlet creates a new extension property on the specified object type.

This cmdlet removes the extended properties from the specified object types.