我正在處理用于組態檔遷移的 USMT 腳本,并遇到一個問題,當我嘗試使用 scanstate.exe 時,它??將退出并顯示代碼 71 -“無法啟動。確保您正在以提升的權限運行 USMT”

uj5u.com熱心網友回復:
由于在腳本塊中您使用來自外部的變數 with $using:,因此您不需要使用-ArgumentList引數發送它們 。
如果您確實想這樣做,請param()在腳本塊中添加一個塊并洗掉using:變數的作用域修飾符。
順便說一句,-ArgumentList采用一組值,而不是腳本塊,我$SourceComputer在第二個示例中省略了變數,因為腳本塊不使用它。
試試這個:
Invoke-Command -ComputerName $SourceComputer -Authentication Credssp -Credential $Credential -Scriptblock {
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Using:SecureKey)
$Key = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
c:\USMTFiles\scanstate.exe "$Using:SharePath\$Using:Username" /i:c:\usmtfiles\printers.xml /i:c:\usmtfiles\custom.xml /i:c:\usmtfiles\migdocs.xml /i:c:\usmtfiles\migapp.xml /v:13 /ui:$Using:Domain\$Using:UserName /c /localonly /encrypt /key:$Key /listfiles:c:\usmtfiles\listfiles.txt /ue:pcadmin /ue:$Using:Domain\*
}
或者:
Invoke-Command -ComputerName $SourceComputer -Authentication Credssp -Credential $Credential -Scriptblock {
param(
$UserName,
$SharePath,
$SecureKey,
$Domain
)
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecureKey)
$Key = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
c:\USMTFiles\scanstate.exe "$SharePath\$Username" /i:c:\usmtfiles\printers.xml /i:c:\usmtfiles\custom.xml /i:c:\usmtfiles\migdocs.xml /i:c:\usmtfiles\migapp.xml /v:13 /ui:$Domain\$UserName /c /localonly /encrypt /key:$Key /listfiles:c:\usmtfiles\listfiles.txt /ue:pcadmin /ue:$Domain\*
} -ArgumentList $UserName,$SharePath,$SecureKey,$Domain
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/362283.html
