2015-11-06 73 views
0

我是一個非常新手的PowerShell。 我剛剛在power shell中學習了腳本hello world。從第一個調用另一個powershell腳本

但是,我有一個任務,我需要完成。

從我的hello world powershell(說'腳本一'),我想調用另一個powershell(說'腳本二'),我可以做。 但在腳本二中,我想通過不同的憑據。

所以腳本一應該用我提到的憑據調用腳本二。

任何人都可以幫助我。

Script One (My first script script) : 
Write-Host 「Hello, World!」 
invoke-expression -Command "C:\Scripts\Script Two.ps1" **[BUT CALL WITH THE CREDENTIALS I WANT]** 

回答

0

在第一個腳本試試這個:

$credential = New-Object System.Management.Automation.PsCredential("OTHERLOGIN", (ConvertTo-SecureString "OTHERPASSOWRD" -AsPlainText -Force)) 

Start-Process powershell.exe -Credential $credential -NoNewWindow -ArgumentList "-File 'C:\Scripts\Script Two.ps1'" 

但是,在一個腳本保持credendials是個壞習慣,所以你可以用這個代替(會提示你輸入登錄/密碼的第二個腳本):

$credential = Get-Credential 
相關問題