Previously I put together two separate how-to articles that show you how to use powershell to setup emailed reports for Citrix servers with disabled logins (http://24x7itconnection.com/2014/02/25/powershell-report-that-will-check-for-citrix-xenapp-servers-with-logins-disabled/) and how to determine how many days it has been since each Citrix server in your farm has rebooted (http://24x7itconnection.com/2014/01/13/use-powershell-to-get-an-e-mailed-report-about-xenapp-6-citrix-server-uptime/?relatedposts_exclude=248).
[wp_ad_camp_1]
This how-to combines the two separate reports into one report into one.
For this Powershell script to work properly you will need to have the following in place:
- Create the following directories on the Citrix server where the powershell will run from c:\healthreport and c:\powershellscripts\healthreport\reports
- Modify the #Email the report to your Citrix Administrators section
- Create a service account that has access to Citrix
- Install the appropriate Citrix XenApp SDK for Powershell
- Save the following code as a .ps1 file
- See the following article and go to the section on how to set this up as a scheduled task in order to routinely automate this script http://24x7itconnection.com/2014/02/25/powershell-report-that-will-check-for-citrix-xenapp-servers-with-logins-disabled/
Add-PSSnapin “Citrix.XenApp.Commands” -ErrorAction SilentlyContinue#Get a list of Citrix servers with Logins Disabled and Add to the html file
[string]$path = “C:\HealthReport\CitrixServerHealth.html”
$logins = Get-XAServer | where {$_.LogonsEnabled -eq $false} | select ServerName, LogonsEnabled | Sort-object -Property LogonsEnabled | ConvertTo-HTML -As Table -body ”
<h1>Citrix Servers with Disabled Logins</h1>
The following report was run on $(get-date)” >> $path
#Create html file and get XenApp Servers sorted alphabetically
[string]$path = “C:\HealthReport\CitrixServerHealth.html”
$servers = Get-XAServer | Sort-Object -Property ServerName#Get uptime for XenAppServers in the Array
Function Get-UpTime
{ Param ([string[]]$servers)
Foreach ($s in $servers)
{
$os = Get-WmiObject -class win32_OperatingSystem -cn $s
New-Object psobject -Property @{computer=$s;
uptime = ((get-date) – ($os.ConvertToDateTime($os.lastbootuptime))).TotalDays}}}
#Add Server data and Uptime information to html file
Get-UpTime -servers $servers |
ConvertTo-Html -As Table -body ”
<h1>Citrix Server Uptime Report</h1>
The following report was run on $(get-date)” >> $path
#Email the Report to your Citrix Administrators
$emailserver = “smtp.domain.com”
$msgfrom = “[email protected]”
$msgto = “[email protected]”
$msgsubject = “Citrix Environment Health Report”
$body = get-content “C:\HealthReport\CitrixServerHealth.html”
$message = New-Object System.Net.Mail.MailMessage $msgfrom, $msgto
$message.subject = $msgsubject
$message.IsBodyHTML = $true
$message.Body = $body
$smtp = New-Object Net.Mail.SmtpClient($emailserver)
$smtp.Send($message)
#Move File with a new Name for reporting
$today = get-date -Displayhint DateTime
Copy-Item C:\HealthReport\CitrixServerHealth.html C:\PowershellScripts\HealthReport\Reports\
rename-item -path C:\HealthReport\Reports\CitrixServerHealth.html -newname Report_$((Get-Date).ToString(‘MM-dd-yyyy_hh-mm-ss’)).html
#Delete the html file
Remove-Item C:\HealthReport\CitrixServerHealth.html -recurse