Hello, sorry for my late reply.
No error in the scheduler task.
this is my test script:
# PowerCLI snappin loading
add-PSSnapin VMware.VimAutomation.core
# A configuration file with $script:VCIP
. ".\VCIP.ps1"
# Env var
$USER=$env:username
$en:appdata="c:\Users\"+$USER+"\Application Data"
try
{
get-process > ".\getprocess.txt"
$vc = connect-VIServer -Server $script:VCIP -ea stop
$allVM = get-vm
write-output $allVM > "out_OK.txt"
}
catch
{
write-output $_ > "catch.txt"
}
finally
{
disconnect-viserver $vc -confirm:$False
remove-PSSnapin VMware.VimAutomation.core
}
We call the local account SCRIPT_USER, witch have the necessary credential stored for VC connection.
When I launch the script in a runas powershell command line, file getprocess.txt and out_ok.txt are created with the corresponding content.
When I launch the script from Windows task scheduler, I have the getprocess.txt file and the catch.txt file. This last file contain an "access is denied" error.
The task: "Run whether user is logged or not (+ Do not store password)", and "Run with highest privileges" are selected.