Wednesday, May 22, 2013

PowerShell script to refresh training environment to most recent snapshot

#Refreshes the training system to the latest snapshot
connect-viserver viserver
$PSEmailserver = "SMTP.companyname.com"
$CurrentTrainingSnap = (get-snapshot Appserver** | sort-object -Property Created -Descending | select-object -ExpandProperty Name -First 1)
Set-VM Appserver** -Snapshot $CurrentTrainingSnap -Confirm:$false
Send-MailMessage -From "emailaddress" -To "emailaddress" -cc "emailaddress" -Subject "Appserver** has been refreshed"
PowerShell script to check for unencrypted computers and send email alert

Computers log any decryption event to a log file , if the log file is older than a day
then the process is assumed to have failed , in this case an email is sent to our helpdesk system which automatically logs a call for the helpdesk staff to contact the end user and manually remediate the device

$PSEmailserver = "SMTP.emailserver.com"
$DateToCompare = (Get-date).addDays(-1)
$PathToCheck = "\\fileserver\emcryptionuninstall$\DecryptLimbo\"
$LimboComputers = get-childitem $PathToCheck | Where-object {$_.lastwritetime -lt $DatetoCompare}
$limbocomputers | ForEach-Object { Send-MailMessage -From "Security@company.ie" -To "me@company.ie" -cc "others@company.ie" -Subject "The following computer has not completed the encryption Process" -Body (get-content $_.fullname)}