Skip to content

Instantly share code, notes, and snippets.

@torgro
Created November 4, 2016 14:41
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 torgro/86dac9e48597f4edf125471b2c871526 to your computer and use it in GitHub Desktop.
Save torgro/86dac9e48597f4edf125471b2c871526 to your computer and use it in GitHub Desktop.
# Added from http://bretty.me.uk/save-money-using-citrix-octoblu-automation-for-power-management/
# Author: Dave Brett
function Lab-Shutdown {
$ErrorActionPreference = 'Continue'
import-module XenServerPSModule
connect-xenserver -url http://xs.bretty.local -username USERNAME -password PASSWORD
$file = "c:\Scripts\vmlist.txt"
$VMNames = Get-Content $file
foreach($VMName in $VMNames)
{
$VM = Get-XenVM -Name $VMName
Write-Host "Scheduling Power off of VM '$VMName'"
Invoke-XenVM -VM $VM -XenAction CleanShutdown -Async
}
Disconnect-XenServer
$From = "xs@bretty.me.uk"
$To = "dave@bretty.me.uk"
$SMTPServer = "xsmail.bretty.me.uk"
$SMTPPort = "25"
$Username = "xs@bretty.me.uk"
$Password = "PASSWORD"
$subject = "bretty.local Lab Shutdown"
$body = "bretty.local - lab has been shutdown"
$smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort);
$smtp.EnableSSL = $false
$smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
$smtp.Send($From, $To, $subject, $body);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment