VMware Horizon Community
curtistcreps
Enthusiast
Enthusiast

PowerCLI script to send message to all desktops in a specific pool

I am working on a PowerCLI script that will filter all sessions within a specific Horizon pool, send a warning message to those filtered sessions via the Session_SendMessage API call, then wait a certain amount of time before logging them off. The filtering and logging off portion does not seem to be the issue, but rather the Session_SendMessage portion. Here is what I have so far: 

Connect-HVServer <server>
$Services1 = $Global:DefaultHVServers.ExtensionData
$Sessions = (Get-HVLocalSession).NamesData
ForEach ($Session in $Sessions) {
IF ($Session.DesktopName -eq "TEST") {
Write-Host `n "Connection to TEST found" $Session.Username }
$Services1.Session.Session_SendMessage($session.id, "INFO", "Your session will be logged out in 10 minutes for maintenance. Please save your work!")
}

 

In order to confirm that $Sessions variable was working correctly I threw in the the Write-Host portion. In the TEST pool I have specified, I do get a return (there is only one session logged into that pool at the moment). The problem is what follows after the API call: 

 

curtistcreps_0-1620052410293.png

 

Not entirely sure what I'm doing wrong...

 

 

0 Kudos
2 Replies
sjesse
Leadership
Leadership

Look at 

 

http://stephenjesse.com/2020/09/16/script-for-automating-desktop-logoffs-in-horizon/

 

its what I use. I email and send a local message and that seems to be working.. It looks similar I'd compare and also make sure your powercli version is updated.

 

$global:DefaultHVServers[0].ExtensionData.Session.Session_SendMessage($session.id,$emailSubject,$emailBody)

 

 

0 Kudos
curtistcreps
Enthusiast
Enthusiast

Thanks for the quick response.

Still no luck. I can confirm that I am on v. 5.1.17763.1007 of PS. Seems that v7 is not plausible (at least from the last time I tried it with PowerCLI due to .NET incompatibilities):

Now I'm seeing this:

curtistcreps_0-1620054200061.png

 

Do you recall what version of PS you used at the time of writing this article? 

 

0 Kudos