Now, when the Windows Powershell Credential Request prompts, there’s a drop down list. Because of the line above, DOMAIN\AdminJoe is already filled in. I was wondering if it’s possible to add multiple accounts to this drop down list, so that a colleague of mine can execute the script with his credentials (without entering his account name over and over again).
The UserName parameter is a string parameter and cannot accept multiple inputs, so it is not possible to have a drop down with multiple inputs.
One way you can do it is by accepting a -Credential parameter and use the Export-CliXml and Import-CliXml cmdlets.
[pre]
param (
[pscredential]$Credential
)
[/pre]
Then, when a colleague calls the script, they can do something like:
[pre]
Export-CliXml -Path “<Some local path>.xml” -InputObject (Get-Credential -UserName <username>
$Credential = Import-CliXml -Path "<Some local path>.xml>
.\Script.ps1 -Credential $Credential
[/pre]
You only need to run the Export-CliXml once and will store in the given location in a secured xml format. Then the Import-CliXml cmdlet will import their credentials, and will only import the credentials from the context of the user that ran the Export-CliXml cmdlet.
I should have formulated myself better i.e. that I had read the help file of Get-Credential (where the UserName parameter didn’t accept multiple inputs). My question was more like if there were any other ways to do this (which you gave me). Some working points for me!