Well, for some reason I'm unable to post a comment to the blog entry here:

http://blogs.vmware.com/PowerCLI/2011/09/list-and-disconnect-vcenter-sessions.htmlโ€‹

... though it was still accepting comments, well, heck, three days ago. Must be work's network rules (though the error is coming from their server, so who knows??).

Anyhow, just for the sake of posterity, here's what I *would've* said about that not-quite-finished script...

<blockquote>$SessionMgr = Get-View $DefaultViserver.ExtensionData.Client.ServiceContent.SessionManager</blockquote>

This isn't great, as if your connection has dropped but $DefaultViserver hasn't cleared out, it'll throw an error. Or, probably more likely, if <q>$DefaultViserver -eq $null</q> because you <i>did</i> bother disconnecting, you'll get, "The property 'ExtensionData' cannot be found on this object. Verify that the property exists," from the same line.

So there's certainly an assumption in this function that you have an active connection when this function is called. Since we're implicitly encouraging folks not to leave connections open, that's not always even the preferred case.

Probably easy enough to handle with <q>$DefaultViserver -eq $null</q> and a throw-catch, as those are possibilities I'd expect this sort of function to catch. Right? ;^)

Labels: