我有该代码:
$Switch = Read-Host "`n`rPlease choose account: `n`r
1. Account 1. `n`r
2. Account 2. `n`r
Please enter the number of the option you would like"
switch ($Switch) {
1 {
$Credentials = New-Object System.Management.Automation.PSCredential x,(‘x’ | ConvertTo-SecureString -AsPlainText -Force)
$password = ConvertTo-SecureString “x” -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential (“x”, $password)
}
2 {
$Credentials = New-Object System.Management.Automation.PSCredential x,(‘x’ | ConvertTo-SecureString -AsPlainText -Force)
$password = ConvertTo-SecureString “x” -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential (“x”, $password)
}
}
#$Credentials = New-Object System.Management.Automation.PSCredential x,(‘x’ | ConvertTo-SecureString -AsPlainText -Force)
$args = "F:\Teams\Files\GISAppTeams.ps1"
Start-Process powershell.exe -Credential $Credentials -ArgumentList ("-file $args")
如何将变量$credential
传递到Start-Process
cmdlet,以便在新的脚本实例中可用?