Skip to content

Instantly share code, notes, and snippets.

@ilandcloud
Created October 12, 2016 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilandcloud/60dacff4d140fc1906466ac3b597f19f to your computer and use it in GitHub Desktop.
Save ilandcloud/60dacff4d140fc1906466ac3b597f19f to your computer and use it in GitHub Desktop.
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
}
}
}
@silinalexandr
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment