Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# Added from
# 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
$From = ""
$To = ""
$SMTPServer = ""
$SMTPPort = "25"
$Username = ""
$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