Hey All,
I am making my first go around with scritping with powercli. I currently have a "script" that consists of two one liners, first line is to to delete a VM and the second line is to create a VM from a clone. Nothing major, I know. What I am trying to figure out is I would like to schedule this script as Windows Task and pass the credentials used to run the task to cmdlet Connect-VIServer that I have at the beginning of the scipt.
Somebody help a rookie out?
TIA,
-Jason
Why don't you let the Scheduled Task run with that specific account ?
That way you don't have to pass credentials to the Connect-VIServer cmdlet, it will use the credentials of user under which the scheduled task runs.
If the above is not possible and you need to pass credentials, have a look at Hal's functions Export-PSCredential and Import-PSCredential.
These will permit you to use a credential in a more secure way than passing them in clear text in your script.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Why don't you let the Scheduled Task run with that specific account ?
That way you don't have to pass credentials to the Connect-VIServer cmdlet, it will use the credentials of user under which the scheduled task runs.
If the above is not possible and you need to pass credentials, have a look at Hal's functions Export-PSCredential and Import-PSCredential.
These will permit you to use a credential in a more secure way than passing them in clear text in your script.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
Thank you for the response...
So maybe my ignornance is showing a bit on this. So if I use the credentials set on the scheduled task do I set the line to connect to vCenter as fllows:
Connect-VIServer <vCenter Server Name>
TIA,
-Jason
That is correct.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you!
Welcome to PowerCLI!
I have noticed that when using the Hal's method that the secure string generated can only be read by the same username that created it. I presume it is part of the algorithm for the ConvertFrom-SecureString and ConvertTo-SecureString cmdlets.
I ran across this when I used a similar function for a similar purpose. Coworker generated a file with secure string conversion so that multiple admins could use it but it would only run for him. I generated my own file with the function and I was able to run it no problem logged in as myself. YMMV
I have a module I'm completing that we're going to use to manage encrypted password files for each user based on username for future scripts. I can notify you once it is complete if you're interested.
...can only be read by the same username that created it.
That is correct, and Hal mentions that in the Purpose text.
I'm very curious to see the module you are developing.
Please post when it's ready.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Indeed. I had not written the original function and also failed to read all of the notes just now. It was good of Hal to include it...great example of why documentation is important for our new PowerCLI'er. Thanks Luc and I'll definitely send it your way as well.