Created
October 12, 2016 14:55
-
-
Save ilandcloud/60dacff4d140fc1906466ac3b597f19f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function New-CIMetaData { | |
<# | |
.SYNOPSIS | |
Creates a Metadata Key/Value pair. | |
.DESCRIPTION | |
Creates a custom Metadata Key/Value pair on a specified vCloud object | |
.PARAMETER Key | |
The name of the Metadata to be applied. | |
.PARAMETER Value | |
The value of the Metadata to be applied. | |
.PARAMETER CIObject | |
The object on which to apply the Metadata. | |
.EXAMPLE | |
PS C:\> New-CIMetadata -Key "Owner" -Value "Alan Renouf" -CIObject (Get-Org Org1) | |
#> | |
[CmdletBinding( | |
SupportsShouldProcess=$true, | |
ConfirmImpact="High" | |
)] | |
param( | |
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)] | |
[PSObject[]]$CIObject, | |
$Key, | |
$Value | |
) | |
Process { | |
Foreach ($Object in $CIObject) { | |
$Metadata = New-Object VMware.VimAutomation.Cloud.Views.Metadata | |
$Metadata.MetadataEntry = New-Object VMware.VimAutomation.Cloud.Views.MetadataEntry | |
$Metadata.MetadataEntry[0].Key = $Key | |
$Metadata.MetadataEntry[0].Value = $Value | |
$Object.ExtensionData.CreateMetadata($Metadata) | |
($Object.ExtensionData.GetMetadata()).MetadataEntry | Where {$_.Key -eq $key } | Select @{N="CIObject";E={$Object.Name}}, Key, Value | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I tried to use the function and got error message "Exception calling "CreateMetadata" with "1" argument(s): " Tag is not expected in requests for version VERSION_5_5.""
It's about 36 line of the code.
Is there any restrictions related to the version vCD?