Running PowerCli scripts in Orchestrator - getting error message: "Not authenticated. Possible cause of this error is that connection was left unused for a while and session has timed out."

I am running a powercli script from System Center 2012 Orchestrator.
I have this code in my script:
function ConnectVIServer([string]$vCenterHost, [string]$vCenterUser, [string]$vCenterPass) {
	Set-PowerCLIConfiguration -DefaultVIServerMode Single -InvalidCertificateAction Ignore -confirm:$false
	Set-PowerCLIConfiguration -WebOperationTimeoutSeconds -1 -Confirm:$False
	Connect-VIServer -Server $vCenterHost -User $vCenterUser -Password $vCenterPass
}

Open in new window


Before each time a powercli cmdlet is called, I check if we have a connection to a vCenter and connect to it if not:

if($global:DefaultVIServers.Count -eq 0 -or $global:DefaultVIServers.Count -lt 0) { ConnectVIServer $vCenterHost $vCenterUser $vCenterPass }

Open in new window


Still I get this error message:
"Not authenticated. Possible cause of this error is that connection was left unused for a while and session has timed out. In such case use Connect-VIServer to reconnect."

If I test the script directly in powershell(Add-PSSnapin VMware.VimAutomation.Core first) or powercli, everything works fine. I checked the vCenter timeout settings and they are on default values (30 seconds for normal operations, 120 for long). I tried changing them to 60 seconds for normal operations and 600 for long, that did not help.

Any suggestions?
LVL 2
itniflAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dipopoCommented:
Is this version 5.1, think it's a known bug either downgrade to v4.1 or:

Set-PowerCLIConfiguration -WebOperationTimeoutSeconds -1
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
itniflAuthor Commented:
As you can see, I am already using:
Set-PowerCLIConfiguration -WebOperationTimeoutSeconds -1
0
itniflAuthor Commented:
Tried upgrading to version 5.5 of Powercli, didn't help much.
0
itniflAuthor Commented:
Now it seems that the whole script runs through nicely, but at the end when I call Disconnect-VIServer I get the infamous error message "- Not authenticated. Possible cause of this error is that connection was left unused for a while and session has timed out. In such case use Connect-VIServer to reconnect."
0
itniflAuthor Commented:
Although your answer was not the solution in my case, I guess it is the closest I can get and that this answer is generally the solution in many cases.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VMware

From novice to tech pro — start learning today.