Skip to content

Instantly share code, notes, and snippets.

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
@ilandcloud
ilandcloud / Get-CIMetadata.ps1
Last active October 13, 2016 13:51
This is a custom-developed cmdlet from velemental.com. This can be referenced as part of your Powershell profile, or just included at the top of your script. http://velemental.com/2012/03/29/managing-metadata-in-vcd-with-powercli/
Function Get-CIMetaData {
<#
.SYNOPSIS
Retrieves all Metadata Key/Value pairs.
.DESCRIPTION
Retrieves all custom Metadata Key/Value pairs on a specified vCloud object
.PARAMETER CIObject
The object on which to retrieve the Metadata.
# Set up an array for the final report
$report = @()
# Get all vApp from the Org
$vApps = Get-CIVApp
foreach ($vApp in $vApps) {
# Get the metadata key/value pairs for all vApps
$Metadatas = Get-CIMetaData -CIObject $vApp
Connect-CIServer -server ‘sin01.ilandcloud.com’ -User ‘username’ -Password ‘password’ -Org ‘YourOrg
# Read existing CSV file with metadata requirements
$file = 'c:\temp\metadata.csv'
# Read the CSV file into an array
$requirements = Import-Csv -Path $file
# Trundle through the array, getting the requirements per vApp
foreach ($requirement in $requirements){
$vApp = $requirement.vApp
# Connect to iland cloud
Connect-CIServer -server ‘sin01.ilandcloud.com’ -User ‘username’ -Password ‘password’ -Org ‘YourOrg
# Get the current time, and specifically hour in 24 hour format
$time = Get-Date -DisplayHint Time
$today = Get-Date -UFormat %a
$hour = $time.Hour
# Get a list of all the vApps in the Org
$vApps = Get-CIVApp
@ilandcloud
ilandcloud / get-CIVapp.ps1
Created October 12, 2016 14:32
The ‘AutoOnOff’ key on its own can be used for a really simple script that checks for the existence of the key and the value being set to ‘Yes’, and will then shut it down.
$vApps = Get-CIVApp
$Metadatas = Get-CIMetaData -CIObject $vApps
foreach ($Metadata in $Metadatas) {
$vApp = $Metadata.CIObject
$Key = $Metadata.Key
$Value = $Metadata.Value
if ($Value -like 'Yes') {write-host 'Stopping vApp....',$vApp}
if ($Value -like 'Yes') {Stop-CIVApp -VApp $vApp -Confirm:$false}
}