Nov
30

The Best VMware View PowerShell Variable – Inform the Users

Running a lot of persistent desktops can have it’s it challenges. While persistent desktops are easier on the infrastructure; like DNS, DHCP, and storage IO they’re a real pain to manage. Since windows is windows, you do need to reboot your windows virtual desktop or else it will eventually get slow by some memory leaking program. It’s kind of funny that all things that a user would put up with a physical desktop, but when it comes to VDI they except the world(this can be good). I think the high exception is because you have given them something that is new and that they’re unsure of.

To help move your users move along their VDI journey, you can tell them how long their virtual desktop has been running my emailing them. Hopefully by letting them know, maybe you can prevent a help desk ticket.

The below code has to run on the View Connection Broker. There might be a better way to get the user’s email address but I don’t know it. If you do please do tell!

Import-Module ActiveDirectory
#need to grab AD information later

$listOfvms = Get-DesktopVM -vc_id (Get-ViewVC -serverName "vCenter").vc_id
#Grab all the desktops that your connection brokers are using,this will pull replica's as well
foreach ( $vms in $listOfvms){

if ($vms.isInPool -eq "true")
{
#if the desktop is in a pool see how long it's been running
$wmi = Get-WmiObject -ComputerName $vms.Name -Query "SELECT LastBootUpTime FROM Win32_OperatingSystem"
$now = Get-Date
$boottime = $wmi.ConvertToDateTime($wmi.LastBootUpTime)
$uptime = $now - $boottime
$d =$uptime.days
$user = Get-ADUser $vms.user_sid #Get AD user info so we can build the email address
$userSID = $vms.user_sid #Best PowerShell Variable b\c it means you know which desktops have been assigned and are active by users

#If the desktop has been running for 7 days and desktop is being used by a user, send an email
if ($d -gt "7"-and $userSID -gt 1){
Write-Host $userSID
$mail = New-Object System.Net.Mail.MailMessage
$user = Get-ADUser $vms.user_sid
$mail = New-Object System.Net.Mail.MailMessage
$emailTo = $user.GivenName + "." + $user.SurName + "@domain.com"
$mail.To.Add($emailTo)
$mail.From = "noreply@domain.com"
Write-Host $mail.From
$mail.Subject = "Your VDI Desktop has been running for " + $d + " days"
$mail.Body = "Your " + $vms.name + " desktop has been running for " + $d + " days. If performance is slow please take the time restart your desktop. To restart your virtual machine please select the option from the Start menu. "
Write-Host $emailTo
$smtp = New-Object System.Net.Mail.SmtpClient("emailserver")
$smtp.Send($mail)
$emailTo = ""
}

$userSID = ""
}
}

Trackbacks

  1. […] The Best VMware View PowerShell Variable – Tell them to Reboot […]

Speak Your Mind

*