Automation

 View Only
  • 1.  Send messages to active connections on Horizons using PowerCLI

    Posted Nov 16, 2020 12:14 PM

    Hi All,
    I am trying to script a warning message to active users in a pool before it gets powered down for Maintenance.
    I cant get the messages to appear on the client side, I think its something to do with the sessionid below not having the right info but I can't seem to figure it out.

    I would be extremely grateful for any help

     

    $credential = Import-CliXml -Path 'C:\Scripts\cred.xml'$hvServices = Connect-HVServer localhost -Credential $credential
    $hvservice=$hvServer.ExtensionData
    $sessions=get-hvlocalsession
    $Poolname="PoolNameHere"
    $WaitTime=1800


    #Disable the Pool and prevent more connections before Maintenance
    Set-HVPool -PoolName $Poolname -Disable
    Write-Host "New connections to $Poolname disabled"

    #Notify current users about maintenance

    foreach ($session in $sessions){

    if($session.DesktopName -eq "$Poolname"){

    $sessionId = $session.Id
    Write-Host "Connection to $Poolname found: " $session.username
    $hvservice.session.Session_SendMessage($sessionid,"INFO","Test")

    }

    }



  • 2.  RE: Send messages to active connections on Horizons using PowerCLI

    Posted Nov 16, 2020 12:19 PM

    Did you try disabling the pool after you send the message?



  • 3.  RE: Send messages to active connections on Horizons using PowerCLI

    Posted Nov 16, 2020 12:32 PM

    Thanks for the reply,
    Ive tried commenting out all the commands for Disabling/Enabling the pools and just letting the foreach loop run but it still wont generate the mesage on the target client for me!



  • 4.  RE: Send messages to active connections on Horizons using PowerCLI

    Posted Nov 17, 2020 09:46 AM

    If I was to change my approach and populate the get-HVlocalsession with a where clause that we would only populate the array with results that were in a specific pool, Any idea how would I select the proper field to allow the Sendmessages command to work?

    $Poolname="PoolNameHere"

    $sessions=get-HVlocalsession | 

    Where{$session.DesktopName -eq "$Poolname"

    Select????}

    $services1.session.Session_SendMessages($sessions.id,"Warning","Test")



  • 5.  RE: Send messages to active connections on Horizons using PowerCLI

    Posted Nov 18, 2020 06:18 AM

    Why do you loop trough the sessions while you can just build a search to get all the sessions in the pool and send the same message at the same time? 

    https://www.retouw.nl/2018/10/30/sending-messages-to-users-with-the-horizon-apis/

    $services1.session.Session_SendMessages($sessions.id,"ERROR","This is a test message with multiple recipients for retouw.nl at 30-10-2018 19:25h")

     yes this uses get-hvlocalsession but you could use a query as well that only looks for sessions in a single pool.



  • 6.  RE: Send messages to active connections on Horizons using PowerCLI

    Posted Nov 18, 2020 08:38 AM

    Thanks for the reply, I have tried both ways but it always seems to come back with the same error!

    It looks like the array is empty but when I look at $sesions it has entries!
    Sorry if I am missing something this is all very new to me

    #Commands I run

    $HVserver=Connect-HVServer -Server........(Server Connection Details)
    $hvservices=$HVServer.ExtensionData
    $sessions=get-HVlocalsession
    $hvservices.session.Session_SendMessages($sessions.id,"Info","PLEASE NOTE")

    #Error it produces
    You cannot call a method on a null-valued expression.
    At line:2 char:1
    + $hvservices.session.Session_SendMessages($sessions.id,"Info","PLEASE ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    #Confirming the array is populated
    PS C:\Windows\system32> $sessions

    Id NamesData ReferenceData SessionData
    -- --------- ------------- -----------
    VMware.Hv.SessionId VMware.Hv.SessionNamesData VMware.Hv.SessionLocalReferenceData VMware.Hv.SessionData
    VMware.Hv.SessionId VMware.Hv.SessionNamesData VMware.Hv.SessionLocalReferenceData VMware.Hv.SessionData

     



  • 7.  RE: Send messages to active connections on Horizons using PowerCLI

    Posted Nov 19, 2020 09:19 PM

    did you also try it with the info in all caps so INFO ? From what I remember that was required