Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect-VIServer fails with "Object reference not set to an instance of an object" #585

Open
guyrleech opened this issue Aug 15, 2022 · 7 comments
Labels

Comments

@guyrleech
Copy link

Describe the bug

Having connected to a vCenter server via Connect-VIserver, when the connection expires, Connect-VIserver will not work again in the same PowerShell instance
connect-viserver error
connect-viserver no error

Reproduction steps

1. Run script https://github.com/guyrleech/VMware/blob/master/VMware%20GUI.ps1 with -server <vcenterserver> and leave the launching PowerShell (v5.1 x64) window open
2. Authenticate to a vCenter server (7.0.3 in my case but not sure it is version specific)
3. Leave for 24 hours
4. Click "Refresh" in the script's GUI and observe to data and error in launching PowerShell window
5. Exit script
6. Launch script again from the same PowerShell window and observe reported error
7. Start a new PowerShell instance and verify script runs ok there (until some hours later when connection has timed out)

Expected behavior

Connect to the given Vcenter server

Additional context

Recently moved from a non-domain joined Windows 10 21H2 laptop where this issue never occurred to a domain-joined Windows 10 21H2 laptop (both where I logon as a non-local admin user and PowerShell is run non-elevated) where the issue occurs 100% of the time.

@guyrleech guyrleech added the bug label Aug 15, 2022
@guyrleech
Copy link
Author

guyrleech commented Aug 24, 2022

I had the same error with a domain joined Server 2019 VM today with version 12.0.0.15939655 and it still does it with a newly launched PowerShell session which it doesn't on my Win10 laptop. Still gives the error after a reboot of the Server 2019 VM so I cannot use PowerCLI on there currently where I could previously.

Output from Trace-Command attached in case it is of use

trace.connect-viserver.log

@kamennikolov
Copy link
Contributor

Turned out there is a limitation of the VAPI endpoint for the length of the session and by default it's set to 24 hours. To change it you have to modify in "/etc/vmware-vapi/endpoint.properties" the values of maxSessionLifespanMilliseconds and minSessionLifespanMilliseconds. By default minSessionLifespanMilliseconds is set to 24 hours and maxSessionLifespanMilliseconds is set to 48. You should change the minSessionLifespanMilliseconds to whatever session length you need and maxSessionLifespanMilliseconds to the same value or higher.

@guyrleech
Copy link
Author

But I should be able to then start a new session, authenticating if necessary - it should not give this error requiring the whole PowerShell session to be restarted. No other vendor's API/SDK I use doe this - it's a bug somewhere in PowerCLI

@kamennikolov
Copy link
Contributor

Yes, this part is a bug in PowerCLI. We'll take a look at it.

@bhumitra
Copy link

Is there any fix for this yet?

@eren-kemer
Copy link

Yes, this part is a bug in PowerCLI. We'll take a look at it.

Hello @kamennikolov
Is there any update to this issue? Facing the same problem while directly connecting to a ESXi Host.
PowerCLI Version 12.7, vSphere 7.0U3.

Need this functionality to connect, restart vmhost, reconnect. Is there any decent workaround for now?
Thanks!

@kamennikolov
Copy link
Contributor

Hi @eren-kemer
We have found the issue and a fix will be available in the next PowerCLI version. The workaround for your case currently is to call Disconnect-VIServer right after the restart. Then you'll be able to re-connect normally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants