I am working on a USMT script for profile migrations and running into an issue where when I try and use scanstate.exe it will exit with code 71 - "Unable to start. Make sure you are running USMT with elevated privileges"
CodePudding user response:
Since in the scriptblock you use the variables from outside with $using:
, you do not need to send them using the -ArgumentList
parameter.
If you do want to do that, add a param()
block in the scriptblock and remove the using:
scope modifier for the variables.
BTW, -ArgumentList
takes an array of values, not a scriptblock, and I have left out the $SourceComputer
variable in the second example because the scriptblock doesn't use it.
Try either this:
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\*
}
or:
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