Skip to content

Instantly share code, notes, and snippets.

@ilandcloud
Last active October 12, 2016 14:52
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/2802e6b8bf75d25c0b860c71c124cc70 to your computer and use it in GitHub Desktop.
Save ilandcloud/2802e6b8bf75d25c0b860c71c124cc70 to your computer and use it in GitHub Desktop.
# 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
foreach ($vApp in $vApps) {
# Get the metadata key/value pairs for all vApps
$Metadatas = Get-CIMetaData -CIObject $vApp
# Get the individual key/value pairs for each vApp
$StopTime = -2
$StartTime = -999
$Day = "Not specified"
foreach ($Metadata in $Metadatas) {
$Key = ''
$Value = ''
$vAppName = $Metadata.CIObject
$Key = $Metadata.Key
$Value = $Metadata.Value
if ($Key -eq 'AutoOnOff') {$AutoOnOff = $Value}
if ($Key -eq 'StopTime') {$StopTime = $Value}
if ($Key -eq 'StartTime') {$StartTime = $Value}
if ($Key -eq 'Days') {$Day = $Value}
if ($Day -like 'Every') {$Day = $today}
}
# Carry out the PowerOn or PowerOff task
if (($hour -ge $StopTime) -and ($vApp.Status -eq 'PoweredOn') -and ($Day -like '*'+$today+'*') -and ($AutoOnOff -eq 'Yes')) {Stop-CIVApp -VApp $vApp -Confirm:$false}
if (($hour -ge $StartTime) -and ($vApp.Status -eq 'PoweredOff') -and ($Day -like '*'+$today+'*') -and ($AutoOnOff -eq 'Yes')) {Start-CIVApp -VApp $vApp -Confirm:$false}
}
Disconnect-CIServer ** -Confirm:$false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment