powershellscripts.com

Tutorials  PowerShell Cmdlet Help for New-VIProperty



NAME
New-VIProperty

SYNOPSIS
Creates a new extension property on the specified object type.

SYNTAX
New-VIProperty [-Name] [-ObjectType] [-Value] [-Force] [-BasedOnExtensionProperty
] [-WhatIf] [-Confirm] []

New-VIProperty [-Name] [-ObjectType] [-Force] [-ValueFromExtensionProperty] [-WhatIf]
[-Confirm] []


DESCRIPTION
Creates a new extension property on the specified object type. Changes take effect upon the next retrieval of the c
orresponding objects.


PARAMETERS
-Name
Specify 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.

Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false

-ObjectType
Specify the object types to which you want to append the new property. All PowerCLI object types are supported.

Required? true
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? true

-Value
Specify a script block you want to use to compute the value of the new extended property.

Required? true
Position? 3
Default value
Accept pipeline input? false
Accept wildcard characters? false

-Force
Indicate that you want to create the new property even if another property with the same name exists for the sp
ecified object type. This parameter is not applicable for core properties of an object type.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-BasedOnExtensionProperty
Specify a list of strings that maps the properties of the $this.ExtensionData object. Use this parameter to spe
cify which members of ExtensionData are used by the script block provided for the Value parameter.
This parameter is case-sensitive.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-WhatIf
Indicate that the cmdlet is run only to display the changes that would be made and actually no objects are modi
fied.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-Confirm
If the value is $true, indicates that the cmdlet asks for confirmation before running. If the value is $false,
the cmdlet runs without asking for user confirmation.

Required? false
Position? named
Default value $true
Accept pipeline input? false
Accept wildcard characters? false

-ValueFromExtensionProperty
Specify a string that maps a property of the $this.ExtensionData object. This parameter is case-sensitive.

Required? true
Position? 3
Default value
Accept pipeline input? false
Accept wildcard characters? false


This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer and OutVariable. For more information, type,
"get-help about_commonparameters".

INPUTS



OUTPUTS
VIProperty


NOTES


On PowerShell 2.0, errors in evaluating values of new properties are not displayed. You can find information ab
out these errors in the $Error environment variable.

-------------- Example 1 --------------

C:\PS>New-VIProperty -ObjectType VirtualMachine -Name CommittedSpaceMB -Value { $vm = $args[0]; $sum = 0; $vm.Exten
sionData.Storage.PerDatastoreUsage | foreach { $sum += $_.Committed} ; $sum = [int]($sum / 1024 / 1024); return $su
m }

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 --------------

C:\PS>New-VIProperty -ObjectType VirtualMachine -Name CommittedSpaceMB -Value { $vm = $args[0]; $sum = 0; $vm.Exten
sionData.Storage.PerDatastoreUsage | foreach { $sum += $_.Committed} ; $sum = [int]($sum / 1024 / 1024); return $su
m } -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 BasedOnExtensionPr
operty parameter to specify which ExtensionData member is used by the script block. This mean that during the cre
ation of each virtual machine, only the specified property of extension data - Storage.PerDatastoreUsage.Committed
will be filled up.





-------------- Example 3 --------------

C:\PS>New-VIProperty -ObjectType VirtualMachine -Name CommittedSpace -ValueFromExtensionProperty 'SUM Storage.PerDa
tastoreUsage.Committed'


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





-------------- Example 4 --------------

C:\PS>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 --------------

C:\PS>New-VIProperty -ObjectType VIObjectCore -Value { if ( $args[0].UId -match "/VIserver=[\w]+@(.*):.*" ) { $matc
hes[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 LINKS
Online version: http://www.vmware.com/support/developer/PowerCLI/PowerCLI501/html/New-VIProperty.html
Get-VIProperty
Remove-VIProperty