Skip to content

Instantly share code, notes, and snippets.

@kacole2
Last active August 29, 2015 14:03
Show Gist options
  • Save kacole2/68e74480bd458d901402 to your computer and use it in GitHub Desktop.
Save kacole2/68e74480bd458d901402 to your computer and use it in GitHub Desktop.
VMware View Active Session Count using PowerCLI
#Add the VMware View powershell snapin
Add-PSsnapin VMware.View.Broker
#Set the connection broker to check. This isn't used since the commands are run locally
$ConnectionServer = "localhost"
#For loggin create a timestamp
$TimeStamp = Get-Date -format yyyy-MM-dd-H-mm
#grab an array of remote sessions
$ActiveConnections = Get-RemoteSession -State CONNECTED
#set initial count to 0
$i = 0
#do some counting
if ($ActiveConnections -eq $NULL){
Echo "there are $i active connections"
}
else{
foreach ($ActiveConnection in $ActiveConnections){
$i++
}
Echo "there are $i active connections"
}
#Add it to a logfile
$row = $TimeStamp + "," + $i + " Active Sessions"
$row | Out-File -FilePath "c:\check-active-sessions.log" -Append
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment