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