VMware Cloud Community
kailabtech
Contributor
Contributor

Vcenter Sessions

Hi All,

I am having problem to terminate the active sessions in Vcenter Server. If I kill the sessions after a minute it creates automatically. (around 30 sessions from same user and not going to ideal anytime). Is there any way I can find the purpose of the sessions and where he initiating the connection (system name) ?

Thanks,

Bala

Tags (1)
0 Kudos
1 Reply
madhusudhanvenu
Contributor
Contributor

Hello kailabtech

Please use the below powershell script and you modify the timings according to your environment requirements. 

$VCServerName = “vcenter name”
$HoursOld = "3" # Modify value at your pleasure
$credsFile = "PowerShellCreds.txt"
$securePassword = Get-Content $CredsFile | ConvertTo-SecureString
$credentials = New-Object System.Management.Automation.PSCredential ("username@vsphere.local", $securePassword)
$VC = Connect-VIServer -Server $VCServerName -Credential $credentials
$ServiceInstance = Get-View ServiceInstance
$SessionManager = Get-View $ServiceInstance.Content.SessionManager
$SessionManager.SessionList |
Where {$_.LastActiveTime -lt (Get-Date).AddHours(-$HoursOld)} |
% {$SessionManager.TerminateSession($_.Key)}
Disconnect-VIServer -Confirm:$False