Skip to content

Instantly share code, notes, and snippets.

@turboBasic
Last active September 2, 2024 16:55
Show Gist options
  • Save turboBasic/8b570842d2165d90909fb2ef3aff98a1 to your computer and use it in GitHub Desktop.
Save turboBasic/8b570842d2165d90909fb2ef3aff98a1 to your computer and use it in GitHub Desktop.
Get-ADK.ps1 - Download & install Windows ADK. #windows #windows-adk #powershell
<#
.SYNOPSIS
Get-ADK: Get and install Windows Assessment and Deployment Kit (WADK)
.DESCRIPTION
Get-ADK is utility for downloading and installing multiple versions of Windows ADK tool.
Usage:
.\Get-ADK.ps1 command [arguments]
commands: download, install, help
'download' <version>: Downloads WADK of specified version to <version> subdirectory of Get-ADK folder. Versions are 14393, 15063, 16299
'install' <version>: Installs WADK of specified version to $ENV:tools directory or b:\tools in ENV:tools isn't defined
'help' or '?'
.EXAMPLE
.\Get-ADK.ps1 download 1709
.EXAMPLE
.\Get-ADK.ps1 install 1607
#>
[CmdletBinding()]
Param(
[Parameter( Mandatory, Position=0 )]
[ValidateScript({
if ( $_.Trim() -notIn 'download', 'install', 'help', '?' ) {
throw "Unknown command '$_'. Commands are: install, download, help"
} else {
$True
}
})]
[String] $Command,
[String] $Version,
[Switch] $noop
)
# Feature Identifier
# Application Compatibility Toolkit (ACT) OptionId.ApplicationCompatibilityToolkit
# Deployment Tools OptionId.DeploymentTools
# Windows Preinstallation Environment (Windows PE) OptionId.WindowsPreinstallationEnvironment
# User State Migration Tool OptionId.UserStateMigrationTool
# Volume Activation Management Tool (VAMT) OptionId.VolumeActivationManagementTool
# Windows Performance Toolkit (WPT) OptionId.WindowsPerformanceToolkit
# Windows Assessment Toolkit OptionId.WindowsAssessmentToolkit
# Windows Assessment Services — Client OptionId.WindowsAssessmentServicesClient
# Windows Assessment Services OptionId.WindowsAssessmentServices
# Microsoft® SQL Server® 2012 Express OptionId.SqlExpress2012
# .NET Framework OptionId.Netfx
$installFeatures = @(
'OptionId.DeploymentTools'
) -join ' '
$versions = @{
'10240' = '1507'
'10586' = '1511'
'14393' = '1607'
'15063' = '1703'
'16299' = '1709'
default = '1803'
}
$installBase = 'b:/tools/ADK'
###############
Write-Host $psBoundParameters
if($ENV:tools) {
$installBase = $installBase -replace 'b:/tools', $ENV:tools
}
if (! $Version) {
$Version = cmd.exe /c ver | ForEach-Object{
if ($_ -match '\d+\.\d+\.(\d+)') { $Matches[1] }
}
if (! $versions.$Version) {
$Version = $versions.default
}
}
switch ($Command) {
'download'
{
$instruction = { & "${psScriptRoot}\${Version}\adksetup.exe" /layout "${psScriptRoot}\${Version}\${Version}_setup_files" }
break
}
'install'
{
$instruction = { & "${psScriptRoot}\${Version}\adksetup.exe" /installpath "${installBase}${Version}" /features $installFeatures }
break
}
{ $_ -in '?', 'help' }
{
$instruction = { Get-Help $psCommandPath }
break
}
}
if ($Debug -or $noop) {
Write-Warning "Debug instruction found. The commands to be executed are:"
Write-Output $instruction
} else {
Invoke-Command -scriptBlock $instruction
}
@davkar3n
Copy link

In case of anyone needs windows 10 userprofile backup and restore scrip.

# Replace the download URL with your desired URL
$downloadUrl = "https://download.microsoft.com/download/8/6/c/86c218f3-4349-4aa5-beba-d05e48bbc286/adk/adksetup.exe"

# Get the path to the user's Downloads folder
$downloadsFolder = Join-Path -Path $env:USERPROFILE -ChildPath "Downloads"

# Extract the filename from the download URL
$fileName = Split-Path -Leaf $downloadUrl

# Combine the destination folder and filename to create the full destination path
$destinationPath = Join-Path -Path $downloadsFolder -ChildPath $fileName

# Download the file using Invoke-WebRequest
Invoke-WebRequest -Uri $downloadUrl -OutFile $destinationPath

# Show a pop-up prompt to inform the user to install the downloaded ADK
Write-Host "The ADK setup file has been downloaded to the following location:"
Write-Host "$destinationPath"
Write-Host "Please run the ADK setup to install the User State Migration Tool (USMT)."

# Wait for the user to press Enter before proceeding
Read-Host "Press Enter to continue after installing the ADK..."

# Replace the following path with the correct path to the ADK installation folder on your system
$adkPath = "C:\ADK"

# Check if the ADK setup is already installed
if (-Not (Test-Path -Path $adkPath -PathType Container)) {
    # Run the ADK setup if it's not installed
    Write-Host "Installing ADK..."
    cd $downloadsFolder
    .\adksetup.exe /quiet /installpath c:\ADK /features OptionId.UserStateMigrationTool

    # Wait for the user to press Enter before continuing
    Read-Host "ADK installation completed. Press Enter to continue..."
}

# Replace the following path with the correct path to the USMT tools on your system
$usmtPath = "C:\ADK\Assessment and Deployment Kit\User State Migration Tool\amd64"

# Add the USMT path to the "Path" system environment variable
[Environment]::SetEnvironmentVariable("Path", $env:Path + ";$usmtPath", [System.EnvironmentVariableTarget]::Machine)

# Show options to the user and read their choice
Write-Host "Please choose an option:"
Write-Host "1. Run scanstate.exe to backup User Profile"
Write-Host "2. Run loadstate.exe to restore User Profile"
$userChoice = Read-Host "Enter the number of your choice (1 or 2)"

cd $usmtPath

if ($userChoice -eq "1") {
    # Get the source username for option 1
    $sourceUsername = Read-Host "Enter the source username for option 1 (e.g., contoso\user1)"

    # Create a new migration store folder on C:\
    $migrationStoreFolder = "C:\MigrationStore"
    if (-Not (Test-Path -Path $migrationStoreFolder -PathType Container)) {
        New-Item -ItemType Directory -Force -Path $migrationStoreFolder
        Write-Host "New migration store folder created at $migrationStoreFolder."
    }

    # Run the scanstate.exe command with the new migration store path and provided source username
    Write-Host "Running scanstate.exe..."
    scanstate.exe $migrationStoreFolder /ue:** /ui:$sourceUsername /i:MigDocs.xml /i:MigApp.xml /o
}
elseif ($userChoice -eq "2") {
    # Get the source and destination usernames for option 2
    $sourceUsername = Read-Host "Enter the source username for option 2 (e.g., contoso\user1)"
    $destinationUsername = Read-Host "Enter the destination username for option 2 (e.g., fabrikam\user1)"

    # Change migration store path to C:\MigrationStore\mystore
    $migrationStorePath = "C:\MigrationStore"

    # Run the loadstate.exe command with the new migration store path and provided usernames
    Write-Host "Running loadstate.exe..."
    $loadstateOutput = loadstate.exe $migrationStorePath /mu:"$sourceUsername":$destinationUsername /i:MigDocs.xml /i:MigApp.xml

    # Check if loadstate.exe completed successfully (exit code 0)
    if ($LASTEXITCODE -eq 0) {
        Write-Host "Option 2 (loadstate.exe) completed successfully."

        # Remove the $migrationStorePath recursively
        Write-Host "Removing migration store path: $migrationStorePath"
        Remove-Item -Path $migrationStorePath -Recurse -Force
    } else {
        Write-Host "Option 2 (loadstate.exe) encountered an error. The migration store will not be removed."
    }
}
else {
    # Invalid choice
    Write-Host "Invalid choice. Please enter 1 or 2."
}

# Wait for the user to press Enter before exiting
Read-Host "Press Enter to exit..."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment