I'm trying to log off sessions for a specific VDI pool after x amount of hours and just can't seem to figure out the last bit. Here is my code
# Connect to the Horizon Connection Server
Connect-HVserver "<Horizon Connection Server>" -User <User Name> -Password <Password> -Domain <Domain>
$sessionSummaries = Get-HVLocalSession
# For each session in the list
ForEach ($SessionSummary in $SessionSummaries)
{
# Record the session id
$SessionId = $SessionSummary.Id
# Record the machine name
$MachineName = $SessionSummary.NamesData.MachineOrRDSServerName
# Get the start time for the session, then find the difference between the current time and the time the session was established
$SessionTime = (New-TimeSpan -Start $SessionSummary.SessionData.StartTime).TotalHours
# Only log the session off if the start time was more than 13 hours ago and is a Call Center VM
If ([int]$SessionTime -gt 13)
{
If ($MachineName -like "<DNS Name Wild Card>*")
{
Write-Host "Machine with name $machineName has been connected for $sessionTime hours."
# Log session off
$hvServices.ExtensionData.Session.Session_Logoff($SessionId)
}
}
}
Disconnect-HVserver -Confirm:$false
When I run this, I get the something like the following:
Any help would be greatly appreciated, looks like it's just not pulling session ID appropriately.
Thanks!
Thanks for taking a look! Grabbing bits and pieces from the internet and missed that part.
When I added this: $hvServices = Connect-HVserver "<Horizon Connection Server>" -User <User Name> -Password <Password> -Domain <Domain>
It worked 🙂
Thanks again!!
Where do you initialise $hvServices?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for taking a look! Grabbing bits and pieces from the internet and missed that part.
When I added this: $hvServices = Connect-HVserver "<Horizon Connection Server>" -User <User Name> -Password <Password> -Domain <Domain>
It worked 🙂
Thanks again!!