regnak2012
Enthusiast
Enthusiast

Credential file being used by another process

Jump to solution

Hi,

I'm using a powercli script query VMs as soon as they are provisioned but if two VMs are built in quick succession it can cause a conflict with the script credential file I use. The relevant section of the script is:

$creds = Get-VICredentialStoreItem -file C:\scripts\cred.xml

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

So, the first iteration of this script grabs the cred.xml and seems to holds onto it until the script completes. Then if a second iteration launches and looks for the cred.xml it fails. The exact error I'm getting is:

The process cannot access the file 'C:\scripts\cred.xml' because it is being used by another process

So, my question is - is there a way to avoid this by adding a check at the start of the script perhaps to check if the file is locked? Then pause for 60 seconds....? Has anyone got something already I could reuse?

Much Appreciated,

Mike

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
0 Kudos
2 Replies
LucD
Leadership
Leadership

Have a look at Powershell: Check if a file is locked


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

0 Kudos
regnak2012
Enthusiast
Enthusiast

Thanks Luc!

Brilliant as usual!

Regards,

Mike

0 Kudos