Link to home
Start Free TrialLog in
Avatar of snyperj
snyperjFlag for United States of America

asked on

Monitoring Server login status

We have a 10 server XenApp 6.5 farm.  Often during the day we have to lock a server out (prohibit logins) for various reasons.  Our probelm is - we are forgetful and do not always rememeber to renable logins afterward.  Is there any way we can set up some type of email alert to show us all 10 server login statuses each morning?   Thinking probably not but thought I would inquire.
Avatar of Coralon
Coralon
Flag of United States of America image

Sure.. that's relatively easy with powershell.
1st upgrade to powershell v3 (minimum)
add-pssnapin -name Citrix* -erroraction silentlycontinue

$ServerStatus = get-xaserver | select-object -property ServerName,LogonsEnabled

$SMTPTo = 'name@domain.tld'
$SMTPFrom = 'DisabledServers@domain.tld'
$SMTPSubject = "Disabled Server List on $(get-date)"
$SMTPBody = "Current server status as of $(get-date)\r\n$ServerStatus"
$SMTPServer = 'mailserver@domain.tld'
$SMTPPort = 25

Send-MailMessage -To $SMTPTo -From $SMTPFrom -Subject $SMTPSubject -Body $SMTPBody -port $SMTPPort

Open in new window


Then just schedule the task to run every morning.

You could even add a line to re-enable the logons:
get-xaserver | where-object { $_.LogonsEnabled -eq 'Disabled' | $_.LogonsEnabled = 'Enabled' }

Open in new window


Coralon
Avatar of snyperj

ASKER

This sounds great, but I am not sure how to customize it for my info?

Can you help?

Lets say I have two three servers and their names are:
XenApp65-XA01, XenApp65-XA02, XenApp65-XA03

How do I enter them?

I tried:
$ServerStatus = get-XenApp65-XA01| select-object -property ServerName,LogonsEnabled

Open in new window


but that causes power shell to error with:
get-XenApp65-XA01 : The term 'get-XenApp65-XA01' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.

Also, we use Exchange for Mail, am I just entering the mail server name here:

$SMTPServer = 'mailserver@domain.tld'

Open in new window


Thanks
with PS command "get-xaserver" you get a list of all XenApp Servers and their configuration.
(try it directly within PS)

but with the script i get the server-names but without Logon-state.
Avatar of snyperj

ASKER

Not sure what I am doing wrongUser generated image
You need to add the citrix snapin first

add-pssnapin -name citrix*

Coralon
Avatar of snyperj

ASKER

Almost there....  I can get the results of the servers in the powershell window, now I just need to get the email to send.  The script keeps telling me that no smtp server is entered, but I have entered the info for our exchange server, which is also what we have entered for the smtp values in our local scan-to-email devices, so I know it is correct.  WHat am I missing?
ee-upload.JPG
ASKER CERTIFIED SOLUTION
Avatar of Coralon
Coralon
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of snyperj

ASKER

I am using 2.0
I modified the script as shown in screen 1.  I get the email now, but the body just says:
"Current server status as of 06/23/2015 18:03:34\r\n "  and that is is...

I cant get the server statuses to show in the body of the email?

If I run
get-xaserver | select-object -property ServerName,LogonsEnabled

Open in new window

in powershell, it DOES show them in the powershell window....

What do I need to modify to get them into the email body?

Thanks
powershell-2.jpg
Avatar of snyperj

ASKER

Thanks
In your .net command all you do is set the smtp body switch to powershell command..

Taking the example from article..

$EmailFrom = "test@cscncoc.com"
$EmailTo = "bjackson@csncoc.com"
$Subject = "Test mail Subject"
$Body = Get-XAServer | select-object -property ServerName,LogonsEnabled | format-table
$SMTPServer = "AFSBS2K11"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 25)
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)

Coralon