These credentials are user speceific (duh) but they are also computer specific. Let's say I was to run a scheduled task that uses The 'ScheduledTaskUser' user, and that this task will run from 'TaskServer'.
In order to make this work, this process must be run on 'TaskServer'!
1. Create the securepassword string from the computer that's going to use it:
read-host -assecurestring | convertfrom-securestring | `
2. When you press enter to execute the command above, you will be on a blank line. Enter the password and press enter.
3. The password is now saved on the computer as a secure string (not in plaintext) in the file that you specified.
4. In your script file, build the credential:
$password = get-content `
c:\temp\ScheduledTask_Credentials.txt | convertto-securestring
$credentials = new-object `
-typename System.Management.Automation.PSCredential `
5. Use the credential. You can pass $credentials anywhere you can use the -credential parameter, like so:
get-wmiobject win32_service `
-computer AnotherServer `
You'll notice above that I used the backtick character ` to allow me to continue the script on the next line. I'm trying to do this more and more for script readability......