VMware Cloud Community
rseekell
Enthusiast
Enthusiast

PowerCLI Gives Up after a Day

I've had this issue for several months:

In PowerShell, I connect to vCenter with Connect-VIServer and it works fine for 24-48 hours.  Then suddenly when I do certain tasks, it acts like I'm not authenticated.

So for example, I can Get-VM just fine, but if I do New-Snapshot, it gives a nasty error:

New-Snapshot: 1/20/2022 12:48:25 PM New-Snapshot One or more errors occurred. (com.vmware.vapi.std.errors.unauthenticated {'messages': [com.vmware.vapi.std.localizable_message {'id': com.vmware.vapi.endpoint.method.authentication.required, 'default_message': Authentication required., 'args': [], 'params': , 'localized':}], 'data': , 'error_type': UNAUTHENTICATED, 'challenge': Basic realm="VAPI endpoint",SIGN realm=b099b508ac36b374aead5848003806e1838f7cc5,service="VAPI endpoint",sts="https://myvsphere.net/sts/STSService/vsphere.local"})

And amazingly, the snapshot still takes place!

Even more perplexing: when I do disconnect-viserver and connect-viserver, it still gives me the same error.  Here's what Get-Task shows me:

Get-Task: 1/20/2022 12:54:39 PM Get-Task One or more errors occurred. (com.vmware.vapi.std.errors.unauthenticated {'messages': [com.vmware.vapi.std.localizable_message {'id': com.vmware.vapi.endpoint.method.authentication.required, 'default_message': Authentication required., 'args': [], 'params': , 'localized':}], 'data': , 'error_type': UNAUTHENTICATED, 'challenge': Basic realm="VAPI endpoint",SIGN realm=b099b508ac36b374aead5848003806e1838f7cc5,service="VAPI endpoint",sts="https://myvsphere.net/sts/STSService/vsphere.local"})

So the only thing I know to do is to close and relaunch PowerShell, which is an inconvenience.

Has anyone else seen this and have any ideas how to repair or prevent?

Thanks in advance!

Reply
0 Kudos
6 Replies
LucD
Leadership
Leadership

Not exactly what you are seeing, but closing/starting your PS session on a regular basis is in any case advisable.
Starting my VSC, where I do my PS and PowerCLI session, is something I do at least daily.
PS and PowerCLI tend to get corruptions internally after a while, I noticed.
Who is to blame, I don't know.

Which PowerCLI and vSphere versions are you using?
Do you use a PS prompt or the VSC?
Which PS version?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
rseekell
Enthusiast
Enthusiast

Hello, thanks for your reply.  

I have had this problem on Windows PowerShell 5.1 and currently on PowerShell 7.x.  I'm on vSphere 7 but if I recall correctly, this issue also occurred on vSphere 6.  I seem to have VMware modules 12.1.0.16...

I always use PowerShell itself directly.  I find it inconvenient to close/reopen PowerShell daily, as I often have tasks that carry over from day to day, plus it prevents multiple authentications every morning.  

Any other advice besides closing PowerShell console when these errors happen?

Reply
0 Kudos
LucD
Leadership
Leadership

Not really.

When my session behaves "strange", the only way out is a stop/start.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
LucD
Leadership
Leadership

I just think of something, are you using an SSO account to authenticate to the VCSA?
Or an account from another authenticator, like for example Active Directory?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
rseekell
Enthusiast
Enthusiast

Hello, after some trial and error, I have learned that running all these steps will reset the VMware PowerCLI authentication without closing PowerShell. 

#disconnect from vCenter 
Disconnect-VIServer
#remove all modules in order of dependency
Remove-Module VMware.VimAutomation.Core
Remove-Module VMware.VimAutomation.Cis.Core
Get-Module vmware* | Remove-Module
#remove vmware variables
Remove-Variable DefaultVIServer
Remove-Variable DefaultVIServers
Remove-Variable UidUtil
#now reconnect
Connect-VIServer
 
This is my draft; there could be more to it. Use with discretion, obviously.
Reply
0 Kudos
LucD
Leadership
Leadership

Glad this works for you, but would you mind explaining what the difference is with simply stopping/starting your PS session is?

And to add, a PS session suffers from corruption as well sometimes.
That is not fixed with your procedure.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos