Import-CliXml : Key not valid for use in specified state

  Kiến thức lập trình

I have a simple powershell script:

Start-Transcript -path "C:testcredmove.log" -append

$credentialPath = "C:testcredcred.xml"

$credential = Import-CliXml -Path $credentialPath

Stop-Transcript 

The script runs fine when I run it in powershell.
Also when I run it in the windows task scheduler there is no problem IF the user that I define in the task is logged on.
When the task runs without the user being logged on than I get this error message:

Import-CliXml : Key not valid for use in specified state

I have encrypted the cred.xml file using the same user and on the same machine.
The task in the task scheduler has the option “Run whether user is logged on or not” checked.

LEAVE A COMMENT