Adding several vSphere 6.5 API examples

This commit is contained in:
William Lam
2016-11-20 09:26:52 -08:00
parent 181add5bfd
commit 2d594cb60d
5 changed files with 233 additions and 0 deletions

29
Scripts/vSphereLogins.ps1 Executable file
View File

@@ -0,0 +1,29 @@
Function Get-vSphereLogins {
<#
.SYNOPSIS Retrieve information for all currently logged in vSphere Sessions (excluding current session)
.NOTES Author: William Lam
.NOTES Site: www.virtuallyghetto.com
.REFERENCE Blog: http://www.virtuallyghetto.com/2016/11/an-update-on-how-to-retrieve-useful-information-from-a-vsphere-login.html
.EXAMPLE
Get-vSphereLogins
#>
if($DefaultVIServers -eq $null) {
Write-Host "Error: Please connect to your vSphere environment"
exit
}
# Using the first connection
$VCConnection = $DefaultVIServers[0]
$sessionManager = Get-View ($VCConnection.ExtensionData.Content.SessionManager)
# Store current session key
$currentSessionKey = $sessionManager.CurrentSession.Key
foreach ($session in $sessionManager.SessionList) {
# Ignore vpxd-extension logins as well as the current session
if($session.UserName -notmatch "vpxd-extension" -and $session.key -ne $currentSessionKey) {
$session | Select Username, IpAddress, UserAgent, @{"Name"="APICount";Expression={$Session.CallCount}}, LoginTime
}
}
}