2017-02-22 58 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,你可能想把我的答案标记为答案,这样可以帮助那些正在寻找类似解决方案的人。 :-) –

相关问题