Contents

PowerShell script to find unregistered vms and send email in xenapp 7.6

Views

Contents

I recently came across a task to check all the unregistered vms in xenapp 7.6. I got the infomation and send email manually. I thought of a script which would do the same and came up with below script:

Script:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

Add-PSSnapin citrix*
$smtpServer = "MAILSERVER.TEST.COM"
$smtpFrom = "FROM EMAIL ID"
$smtpTo = "TO EMAIL ID"
$messageSubject = ("Unregistered VMs on XenApp 7.6 Farm " + (Get-Date -format R))

$a = "<style>"
$a = $a + "TABLE {border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH {border-width: 1px;padding: 3px;border-style: solid;border-color: black;background-color: #dddddd;}"
$a = $a + "TD {border-width: 1px;padding: 3px;border-style: solid;border-color: black;}"
$a = $a + "</style>"

$message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto
$message.Subject = $messageSubject
$message.IsBodyHTML = $true
$pre = @"

<h3>List of VMs unregistered in XA 7.6 farm</h3>

"@

$post = @"
<p>
Thanks,<br>SIGNATURE.
</p>
"@

$message.Body = Get-BrokerDesktop | ? {$_.RegistrationState -eq "unregistered"} | select HostedMachineName, RegistrationState | ConvertTo-Html -Head $a -PreContent $pre -PostContent $post
$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($message)

Want to learn more on Citrix Automations and solutions???

Subscribe to get our latest content by email.

If you like our content, please support us by sponsoring on GitHub below: