Try these.
Short answer. Prompt for the creds in the beginning of your script.
$LSCred = Get-Credential
Long answer.
Local creds
$LID = Read-Host "Enter local admin ID"
$LPwd = Read-Host -assecurestring "Enter local PWD"
$LSPwd = Runtime.InteropServices.Marshal::PtrToStringAuto(
Runtime.InteropServices.Marshal::SecureStringToBSTR($LPwd))
$LSPword = ConvertTo-SecureString $LSPwd -AsPlainText -Force
$LSCred = New-Object System.Management.Automation.PSCredential $LID, $LSPword
If the server is an AD member server add the servername to the $LID.
$LID = Read-Host "Enter local admin ID"
$LPwd = Read-Host -assecurestring "Enter local PWD"
$LSPwd = Runtime.InteropServices.Marshal::PtrToStringAuto(
Runtime.InteropServices.Marshal::SecureStringToBSTR($LPwd))
$LSPword = ConvertTo-SecureString $LSPwd -AsPlainText –Force
$SLID = $Server + “\” + $LID
$LSCred = New-Object System.Management.Automation.PSCredential $SLID, $LSPword
Pass $LSCred to your –Cred
Progress bar
$i=0
$l=($vms).length
Foreach($vm in $vms) {
your script code
Write-Progress -Activity "Creating VM progress" -Status "Completed % $i of $l" -PercentComplete (100*$i/$l)
$i++
}
Hope this helps,
JayLB