VMware Cloud Community
heskez
Contributor
Contributor
Jump to solution

VIcredentialstoreitem file locked

Hi There,

I've a question concerning the vicredentialstoreitem. At first a create a credential xml file with the new-vicredentialstoreitem cmdlet.

I use this script to use the credentials for viserver. I run this script in scheduled tasks.

$creds = Get-VICredentialStoreItem -file d:\credfile

Connect-VIServer -Server $creds.Host -user $creds.User -password $creds.Password

The account I use to login VIserver is Domain admin, and the same account I use for scheduling the script.

When scheduled tasks fires up the script I get this error message:

"Could not aquire access to credential file: d:\credfile . Another process/thread has locked the file"

When I run the script from PowerCli, no problem.

Ideas anyone?

Regards

0 Kudos
1 Solution

Accepted Solutions
aevrov
VMware Employee
VMware Employee
Jump to solution

Hi again,

I have a suggestion about what the problem is. Can you check the permissions of the

credentials file that you use? When you create the file with

New-VICredStoreItem it assigns read permissions only to the current user

that the process is running under. This makes sense, since you don't want someone else to read you passwords. Perhaps you've created the file with one user account and try to read it under another.

Let me know if this helped.

Regards,

-Angel

View solution in original post

0 Kudos
7 Replies
LucD
Leadership
Leadership
Jump to solution

Could it be that your PowerCLI session has a lock open on the XML file ?

Try closing your PowerCLI session before you run the scheduled task.

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
heskez
Contributor
Contributor
Jump to solution

Thanks for the reply,

I killed the powershell.exe process and ran the script again.

No, still the same error message.

0 Kudos
heskez
Contributor
Contributor
Jump to solution

Still no solution for this?

0 Kudos
aevrov
VMware Employee
VMware Employee
Jump to solution

Hi Heskez,

Can you check which process has locked the file? You can use some tool like Process Explorer. If the file is locked by the same PowerCLI session, please report back, since this would be a bug.

Regards,

-Angel

0 Kudos
heskez
Contributor
Contributor
Jump to solution

Thanks for the reply

This is the only handle I can find with psexplorer :

D:\Program Files\vmware\Infrastructure\vSphere PowerCLI\VMware.Security.CredentialStore.dll

Which is held by powershell.exe

De file with the credentials I call "credfile" isn't been found between the handles, weird huh?

I don't give an exit ps command in the script itself, only e "disconnect-viserver" at the end.

Is this required?

Regards,

Erik

0 Kudos
aevrov
VMware Employee
VMware Employee
Jump to solution

Hi again,

I have a suggestion about what the problem is. Can you check the permissions of the

credentials file that you use? When you create the file with

New-VICredStoreItem it assigns read permissions only to the current user

that the process is running under. This makes sense, since you don't want someone else to read you passwords. Perhaps you've created the file with one user account and try to read it under another.

Let me know if this helped.

Regards,

-Angel

0 Kudos
heskez
Contributor
Contributor
Jump to solution

I've tested it and you're totally right! Points awarded!

0 Kudos