eggs

Another seemingly insignificant comment from an insignificant guy involving PowerShell.  However, in this case, it’s not PowerShell.  It’s how an external command sequence is being shoved into the Start-Process parameter line.

In this case, a friend is trying to install Windows 10 ADK from a command line (via PowerShell) and specify only three (3) of the optional features.  Reading the command line reference (here), he was putting together the ArgumentList parameter as follows…

"/quiet /norestart /installpath `"$InstallPath`" /features $FeatureList /quiet /norestart"

So the complete statement was something like this…

$InstallPath = "E:\ADK10"
$FeatureList = "OptionId.DeploymentTools OptionId.WindowsPreinstallationEnvironment OptionId.UserStateMigrationTool"

$AdkArgs = "/quiet /norestart /installpath `"$InstallPath`" /features $FeatureList"
$proc = Start-Process $AdkExe -ArgumentList $AdkArgs -NoNewWindow -PassThru

$proc.WaitForExit()
if ($proc.ExitCode -ne 0) {
 Write-Error "ERROR: Windows 10 ADK installation failed with exit code: $($proc.ExitCode)"
}

But every time this was executed, it bombed with the following error message:

ERROR: Windows 10 ADK installation failed with exit code: 1001
 + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
 + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException

Running NET HELPMSG 1001 returns “Recursion too deep; the stack overflowed.”

The first thought in his head was that the entire statement was somehow too long for the command line (255 chars for legacy CMD.exe, I believe).  But that wasn’t it at all.  The solution was unveiled by simply running the command statement from the console without using Start-Process.

As it turned out, the problem was that “/quiet” and “/norestart” have to be called AFTER the /installpath and /features arguments.  Sequence matters a lot.  Apparently, “/features” and “/installpath” have to come first.

The code which works just fine is as follows (note the change in order of parameters inside the $AdkArgs string):

$InstallPath = "E:\ADK10"
$FeatureList = "OptionId.DeploymentTools OptionId.WindowsPreinstallationEnvironment OptionId.UserStateMigrationTool"

$AdkArgs = "/features $FeatureList /installpath `"$InstallPath`" /quiet /norestart"
$proc = Start-Process $AdkExe -ArgumentList $AdkArgs -NoNewWindow -PassThru

$proc.WaitForExit()
if ($proc.ExitCode -ne 0) {
  Write-Error "ERROR: Windows 10 ADK installation failed with exit code: $($proc.ExitCode)"
}

The point of this is that before blaming PowerShell, try running statements like this separately without PowerShell, to verify they indeed work.

DISCLAIMER:  All of the code you see herein could likely be done more efficiently and more appropriately by a blind monkey on LSD.

 

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s