Created
August 2, 2018 02:50
-
-
Save Chirishman/d058ce187fb19e27d781047986f620d2 to your computer and use it in GitHub Desktop.
Windows Assessment and Deployment Kit - Deployment and Imaging Tools Environment Setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Echo off | |
REM | |
REM Sets the PROCESSOR_ARCHITECTURE according to native platform for x86 and x64. | |
REM | |
IF /I %PROCESSOR_ARCHITECTURE%==x86 ( | |
IF NOT "%PROCESSOR_ARCHITEW6432%"=="" ( | |
SET PROCESSOR_ARCHITECTURE=%PROCESSOR_ARCHITEW6432% | |
) | |
) ELSE IF /I NOT %PROCESSOR_ARCHITECTURE%==amd64 ( | |
@echo Not implemented for PROCESSOR_ARCHITECTURE of %PROCESSOR_ARCHITECTURE%. | |
@echo Using "%ProgramFiles%" | |
SET NewPath="%ProgramFiles%" | |
goto SetPath | |
) | |
REM | |
REM Query the 32-bit and 64-bit Registry hive for KitsRoot | |
REM | |
SET regKeyPathFound=1 | |
SET wowRegKeyPathFound=1 | |
SET KitsRootRegValueName=KitsRoot10 | |
REG QUERY "HKLM\Software\Wow6432Node\Microsoft\Windows Kits\Installed Roots" /v %KitsRootRegValueName% 1>NUL 2>NUL || SET wowRegKeyPathFound=0 | |
REG QUERY "HKLM\Software\Microsoft\Windows Kits\Installed Roots" /v %KitsRootRegValueName% 1>NUL 2>NUL || SET regKeyPathFound=0 | |
if %wowRegKeyPathFound% EQU 0 ( | |
if %regKeyPathFound% EQU 0 ( | |
@echo KitsRoot not found, can't set common path for Deployment Tools | |
goto :EOF | |
) else ( | |
SET regKeyPath=HKLM\Software\Microsoft\Windows Kits\Installed Roots | |
) | |
) else ( | |
SET regKeyPath=HKLM\Software\Wow6432Node\Microsoft\Windows Kits\Installed Roots | |
) | |
FOR /F "skip=2 tokens=2*" %%i IN ('REG QUERY "%regKeyPath%" /v %KitsRootRegValueName%') DO (SET KitsRoot=%%j) | |
REM | |
REM Build the D&I Root from the queried KitsRoot | |
REM | |
SET DandIRoot=%KitsRoot%Assessment and Deployment Kit\Deployment Tools | |
REM | |
REM Construct the path to WinPE directory, architecture-independent | |
REM | |
SET WinPERoot=%KitsRoot%Assessment and Deployment Kit\Windows Preinstallation Environment | |
SET WinPERootNoArch=%KitsRoot%Assessment and Deployment Kit\Windows Preinstallation Environment | |
REM | |
REM Construct the path to DISM, Setup and USMT, architecture-independent | |
REM | |
SET WindowsSetupRootNoArch=%KitsRoot%Assessment and Deployment Kit\Windows Setup | |
SET USMTRootNoArch=%KitsRoot%Assessment and Deployment Kit\User State Migration Tool | |
REM | |
REM Constructing tools paths relevant to the current Processor Architecture | |
REM | |
SET DISMRoot=%DandIRoot%\%PROCESSOR_ARCHITECTURE%\DISM | |
SET BCDBootRoot=%DandIRoot%\%PROCESSOR_ARCHITECTURE%\BCDBoot | |
SET ImagingRoot=%DandIRoot%\%PROCESSOR_ARCHITECTURE%\Imaging | |
SET OSCDImgRoot=%DandIRoot%\%PROCESSOR_ARCHITECTURE%\Oscdimg | |
SET WdsmcastRoot=%DandIRoot%\%PROCESSOR_ARCHITECTURE%\Wdsmcast | |
REM | |
REM Now do the paths that apply to all architectures... | |
REM | |
REM Note that the last one in this list should not have a | |
REM trailing semi-colon to avoid duplicate semi-colons | |
REM on the last entry when the final path is assembled. | |
REM | |
SET HelpIndexerRoot=%DandIRoot%\HelpIndexer | |
SET WSIMRoot=%DandIRoot%\WSIM | |
REM | |
REM Set ICDRoot. ICD is X86 only | |
REM | |
SET ICDRoot=%KitsRoot%Assessment and Deployment Kit\Imaging and Configuration Designer\x86 | |
REM | |
REM Now buld the master path from the various tool root folders... | |
REM | |
REM Note that each fragment above should have any required trailing | |
REM semi-colon as a delimiter so we do not put any here. | |
REM | |
REM Note the last one appended to NewPath should be the last one | |
REM set above in the arch. neutral section which also should not | |
REM have a trailing semi-colon. | |
REM | |
SET NewPath=%DISMRoot%;%ImagingRoot%;%BCDBootRoot%;%OSCDImgRoot%;%WdsmcastRoot%;%HelpIndexerRoot%;%WSIMRoot%;%WinPERoot%;%ICDRoot% | |
:SetPath | |
SET PATH=%NewPath:"=%;%PATH% | |
REM Set current directory to DandIRoot | |
cd /d "%DandIRoot%" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#region 001-017 and 098-099 - Very unclear on why this is adding to the path | |
# Looks like it would flow into 100-102 which would try to change directory to a folder which has not been defined | |
$PROCESSOR_ARCHITECTURE = ( | |
if ($env:PROCESSOR_ARCHITECTURE -eq 'x86' -and $env:PROCESSOR_ARCHITEW6432) { | |
$env:PROCESSOR_ARCHITEW6432 | |
} elseif ($env:PROCESSOR_ARCHITECTURE -ne 'AMD64'){ | |
Write-Warning -Message "Not implemented for Processor Architecture $env:PROCESSOR_ARCHITECTURE" | |
$env:Path = ($env:ProgramFiles,$env:Path) -join ';' | |
} else { | |
$env:PROCESSOR_ARCHITECTURE | |
} | |
) | |
#endregion | |
#region 018-043 | |
$KitsRoot = @( | |
'HKLM:\Software\Wow6432Node\Microsoft\Windows Kits\Installed Roots', | |
'HKLM\Software\Microsoft\Windows Kits\Installed Roots' | |
) | %{ | |
Get-ItemProperty $_ -Name 'KitsRoot10' -ErrorAction SilentlyContinue | Select -ExpandProperty KitsRoot10 | |
} | ?{$_} | |
if (-not $KitsRoot){ | |
throw "KitsRoot not found, can't set common path for Deployment Tools" | |
} | |
#endregion | |
#region 044-061 | |
#Deployment And Imaging Root | |
$ADKPath = Join-Path -Path $KitsRoot -ChildPath 'Assessment and Deployment Kit' | |
$NewPathItems = [System.Collections.ArrayList]::new() | |
$NewPathItems = @( | |
'Deployment Tools', | |
'Windows Preinstallation Environment'#, | |
#'Windows Setup', | |
#'User State Migration Tool' | |
) | %{ | |
[void]$NewPathItems.Add((Join-Path -Path $ADKPath -ChildPath $_)) | |
} | |
#endregion | |
#region 062-070 | |
$ThisArchPath = Join-Path -Path $NewPathItems[0] -ChildPath $PROCESSOR_ARCHITECTURE | |
@( | |
'DISM', | |
'Imaging', | |
'BCDBoot', | |
'Oscdimg', | |
'Wdsmcast' | |
)|%{ | |
[void]$NewPathItems.Add((Join-Path -Path $ThisArchPath -ChildPath $_)) | |
} | |
#endregion | |
#region 071-085 | |
@( | |
'HelpIndexer', | |
'WSIM' | |
) | %{ | |
[void]$NewPathItems.Add((Join-Path -Path $NewPathItems[0] -ChildPath $_)) | |
} | |
[void]$NewPathItems.Add((Join-Path -Path $ADKPath -ChildPath 'Imaging and Configuration Designer\x86')) | |
#endregion | |
#region 086-102 | |
$env:Path = (($NewPathItems -join ';'),$env:Path) -join ';' | |
Push-Location $NewPathItems[0] | |
#endregion | |
#region Defined but Never Used In The Original (in case something breaks) | |
# WinPERootNoArch=%KitsRoot%Assessment and Deployment Kit\Windows Preinstallation Environment | |
#SET WindowsSetupRootNoArch=%KitsRoot%Assessment and Deployment Kit\Windows Setup | |
#SET USMTRootNoArch=%KitsRoot%Assessment and Deployment Kit\User State Migration Tool | |
#endregion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment