OON1
Contributor
Contributor

Occasional error DefaultVIServer system variables

Hello,

I occasionally get this error: 

You have modified the global:DefaultVIServer and global:DefaultVIServers system variables. This is not allowed. Please reset them to $null and reconnect to the vSphere server.

I have tried to fix the issue with this piece of code: 

Set-PowerCLIConfiguration -DefaultVIServerMode Multiple -Confirm:$false | Out-Null
$settings=@{
Scope="AllUsers"
DefaultVIServerMode="Multiple"
ProxyPolicy="NoProxy"
ParticipateInCeip=$false
DisplayDeprecationWarnings=$false
WebOperationTimeoutSeconds="-1"
}
Set-PowerCLIConfiguration @Settings -Confirm:$false

 

I still get the error from time to time. How can I avoid this error?

0 Kudos
4 Replies
LucD
Leadership
Leadership

Are you doing anything with Runspaces?
From which environment do you run your PowerCLI scripts?


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

0 Kudos
OON1
Contributor
Contributor

Hello @LucD 

I expose some functionality through a webservice, asp.net mvc.

Each user can then call some functions in a powershell script which resides on the webservice server.

A new powershell instance is created for each powershell function call. Multiple instances may be executing simultaneously.

0 Kudos
LucD
Leadership
Leadership

And that is probably the cause of the errors, PowerCLI is not threadsafe.

You might want to look at the Get-PowerCLIContext and Use-PowerCLIContext cmdlets that were introduced in PowerCLI 12.2
See also New Release – VMware PowerCLI 12.2


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

0 Kudos
OON1
Contributor
Contributor

Thanks a lot i will look into that!

0 Kudos