2017-02-22 101 views
0

我已經寫了一個驗證腳本,其中包含幾個測試,腳本在每臺計算機上藉助工具在本地運行。但是,僅在腳本部分下方成功運行要調用的域用戶名和密碼。Powershell腳本需要調用的域用戶名和密碼

誰能幫我添加用戶名和密碼來調用下面的腳本(如:用戶名:OIM \ test,密碼:測試@ 123)

if (($ImageName -like "*devel*") -or ($ImageName -like "*hosted*")) 
    { 
     #$ADE1 = Invoke-Expression ('C:\ade\bin\ade.exe | select-string -pattern "begintrans"') | out-string ; $ADE = $ADE1.trim().split("")[1] 
     Invoke-Expression ('C:\ade\bin\ade.exe | select-string -pattern "begintrans"') > C:\Temp\ade_check.txt 
     $ADE1 = Get-Content C:\Temp\ade_check.txt | Select-String "begintrans" | out-string ; $ADE = $ADE1.trim().split(" ")[1] 


     if ($ADE -eq "begintrans") 
     { 
     $ADE = "ADE Installation Success" 


     Add-Content $report "<tr>" 
      Add-Content $report "<td bgcolor= 'White' height='30' align=center><B>17</B></td>" 
     Add-Content $report "<td bgcolor= 'White' height='30' align=left><B>ADE</B></td>" 
     Add-Content $report "<td bgcolor= 'Aquamarine' height='30' align=left><B>$ADE</B></td>" 
     Add-Content $report "</tr>" 

echo "ADE = ADE Installation Success" 

     } 

     if ($ADE -eq $null){ 
     $ADE = "ADE Installation Failed" 


     Add-Content $report "<tr>" 
     Add-Content $report "<td bgcolor= 'White' height='30' align=center><B>17</B></td>" 
     Add-Content $report "<td bgcolor= 'White' height='30' align=left><B>ADE</B></td>" 
     Add-Content $report "<td bgcolor= 'red' height='30' align=left><B>$ADE</B></td>" 
     Add-Content $report "</tr>" 

echo "ADE = ADE Installation Failed" 
     } 

    } 
    else 
     { 
     if (($ImageName -like "*simple*") -or ($ImageName -like "*BareOS*")){ 

     $ADE = "BareOS, ADE Not Installed" 


     Add-Content $report "<tr>" 
     Add-Content $report "<td bgcolor= 'White' height='30' align=center><B>17</B></td>" 
     Add-Content $report "<td bgcolor= 'White' height='30' align=left><B>ADE</B></td>" 
     Add-Content $report "<td bgcolor= 'Yellow' height='30' align=left><B>$ADE</B></td>" 
     Add-Content $report "</tr>" 

echo "ADE = BareOS, ADE Not Installed" 
     } 
     } 

回答

0

你想用調用命令 cmdlet的來代替。它有-Credentials你想要的參數。像這樣:

$UserName='oim\test' 
$UserPassword='[email protected]' 
$Password = (ConvertTo-SecureString -String $UserPassword -AsPlainText -Force) 
$Credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList @($UserName, $Password) 
Invoke-Command -ScriptBlock { & 'C:\ade\bin\ade.exe' | Select-String -Pattern 'begintrans' > C:\Temp\ade_check.txt } -Credential $Credentials -ComputerName $env:COMPUTERNAME 
+0

非常感謝基里爾。它工作完美 – SNair

+0

@SNair,你可能想把我的答案標記爲答案,這樣可以幫助那些正在尋找類似解決方案的人。 :-) –

相關問題