# Extract unattend XSD from Windows ADK
Define where the XSD schema should be saved, incl the filename
$out = "$env:USERPROFILE\unattend_win_10.xsd"
Download Windows ADK 10.1.25398.1
Write-Output 'Downloading Windows ADK ...'
$adksetup = Start-BitsTransfer 'https://go.microsoft.com/fwlink/?linkid=2243390' -Destination "$env:TEMP/adksetup.exe"
switch ($adksetup.JobState) {
'Transferred' {
Complete-BitsTransfer -BitsJob $adksetup
Write-Output 'Windows ADK downloaded.'
break
}
'Error' {
throw 'Error downloading Windows ADK.'
}
}
Download .NET Framework 4.7.2 Developer Pack
Write-Output 'Downloading .NET Framework 4.7.2 Developer Pack ...'
$dotnet = Start-BitsTransfer 'https://go.microsoft.com/fwlink/?linkid=2243390' -Destination "$env:TEMP/dotnet_4.7.2_dev_pack.exe"
switch ($dotnet.JobState) {
'Transferred' {
Complete-BitsTransfer -BitsJob $dotnet
Write-Output '.NET Framework 4.7.2 Developer Pack downloaded.'
break
}
'Error' {
throw 'Error downloading .NET Framework 4.7.2 Developer Pack.'
}
}
Install Deployment Tools feature from Windows ADK
Write-Output 'Installing Windows ADK ...'
Start-Process -Wait "$env:TEMP\adksetup.exe" -ArgumentList '/q /features OptionId.DeploymentTools /norestart /ceip off'
Write-Output 'Windows ADK installed.'
Install .NET Framework 4.7.2 Developer Pack
Write-Output 'Installing .NET Framework 4.7.2 Developer Pack ...'
Start-Process -Wait "$env:TEMP\dotnet_4.7.2_dev_pack.exe"
Write-Output '.NET Framework 4.7.2 Developer Pack installed.'
if (!(Test-Path "${env:ProgramFiles(x86)}\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7.2 Tools\ildasm.exe" -PathType Leaf)) {
throw 'Could not find ildasm.exe.'
}
if (!(Test-Path "${env:ProgramFiles(x86)}\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\WSIM\amd64\microsoft.componentstudio.componentplatforminterface.dll" -PathType Leaf)) {
throw 'Could not find microsoft.componentstudio.componentplatforminterface.dll.'
}
Extract the resources embedded in microsoft.componentstudio.componentplatforminterface.dll
Write-Output 'Extracting the XSD schema embedded in microsoft.componentstudio.componentplatforminterface.dll'
& "${env:ProgramFiles(x86)}\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7.2 Tools\ildasm.exe" "${env:ProgramFiles(x86)}\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\WSIM\amd64\microsoft.componentstudio.componentplatforminterface.dll" /Output="$env:TEMP\out.il"
if (!(Test-Path "$env:TEMP\Microsoft.ComponentStudio.ComponentPlatformInterface.MyResources.resources" -PathType Leaf)) {
throw 'Could not find Microsoft.ComponentStudio.ComponentPlatformInterface.MyResources.resources.'
}
Get content from the input file
$fileContent = Get-Content -Path "$env:TEMP\Microsoft.ComponentStudio.ComponentPlatformInterface.MyResources.resources" -Raw
Regular expression (Regex) of the given start and end patterns
$pattern = '(?is)({0}.*?{1})' -f [regex]::Escape('<?xml version='), [regex]::Escape('</xsd:schema>')
Perform the Regex operation and save it to file
[regex]::Match($fileContent, $pattern).Groups[1].Value | Set-Content -Path "$out"
if (!(Test-Path "$out" -PathType Leaf)) {
throw "Could not find $out."
}
Write-Output 'The XSD schema extracted.'
Clean up
Remove-Item "$env:TEMP\Microsoft.ComponentStudio.ComponentPlatformInterface.DistributionShareResources.resources", "$env:TEMP\Microsoft.ComponentStudio.ComponentPlatformInterface.MyResources.resources", "$env:TEMP\adksetup.exe", "$env:TEMP\dotnet_4.7.2_dev_pack.exe", "$env:TEMP\out.il", "$env:TEMP\out.res"