Syntax
New-VIProperty [-Name] <String> [-ObjectType] <String[]> [-Value] <ScriptBlock> [-Force] [-BasedOnExtensionProperty <String[]>] [-WhatIf] [-Confirm] [<CommonParameters>]Related Commands
Online versionDetailed Description
This cmdlet creates a new extension property on the specified object type. Changes take effect upon the next retrieval of the corresponding objects.Parameters
Return Type
The newly created VIProperty objectNotes
In PowerShell 2.0, errors in evaluating values of new properties are not displayed. You can find information about these errors in the $Error environment variable.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.