75 lines
3.2 KiB
PowerShell
75 lines
3.2 KiB
PowerShell
|
|
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
|
|
Start-Process powershell -Verb runAs -Args "$PSScriptRoot\mdt-ds2usb.ps1"
|
|
Exit
|
|
}
|
|
Write-Host "Script is running as administrator. Continuing..."
|
|
|
|
cd $PSScriptRoot # in case script is run from other location
|
|
|
|
#SETUP
|
|
|
|
Add-PSSnapin -Name Microsoft.BDD.PSSnapIn
|
|
|
|
#PATH VARIABLES
|
|
$RemoteDS = $args[0]
|
|
$LocalDS = "C:\ds_share"
|
|
$MediaPath = "C:\ds_media"
|
|
$MediaDS = $MediaPath + "\Content\Deploy"
|
|
$CustomSettings = $MediaDS + "\Control\CustomSettings.ini"
|
|
$ISOName = $args[1]
|
|
|
|
#CLEANUP
|
|
echo "Preparing Environment..."
|
|
# remove possible conflicting ps drives
|
|
$psDrivesToRemove = Get-PSDrive -PSProvider MDTProvider
|
|
foreach ($psDrive in $psDrivesToRemove) {
|
|
Remove-PSDrive -Name $psDrive.Name -Force
|
|
}
|
|
# remove existing contents of local directories
|
|
$paths = "$LocalDS", "$MediaPath"
|
|
foreach ($path in $paths) {
|
|
if (Test-Path -LiteralPath $path) {
|
|
Remove-Item -LiteralPath $path -Recurse -Force
|
|
}
|
|
}
|
|
|
|
#PREP DIRECTORIES
|
|
echo "Creating Directories"
|
|
new-psdrive -name DS_USB -psprovider mdtprovider -root $LocalDS | out-null
|
|
New-Item -Path $MediaPath -ItemType Directory | out-null
|
|
|
|
#CLONE REMOTE DEPLOYMENT SHARE LOCALLY
|
|
echo "Copying Remote Files to Local Deployment Share... This might take a while!"
|
|
robocopy $RemoteDS $LocalDS /IM /IS /IT /E /ZB /JOB:"$PSScriptRoot/exclude.rcj" | out-null
|
|
|
|
#CREATE MEDIA ITEM IN LOCAL DEPLOYMENT SHARE
|
|
echo "Adding Media Item to Local Deployment Share..."
|
|
New-item -path "DS_USB:\Media" -enable "True" -Name "MEDIA001" -Comments "" -Root $MediaPath -SelectionProfile "Everything" -SupportX86 "False" -SupportX64 "True" -GenerateISO "True" -ISOName $ISOName -Verbose | out-null
|
|
new-PSDrive -Name "MEDIA001" -PSProvider "MDTProvider" -Root $MediaDS -Description "Embedded media deployment share" -Force -Verbose | out-null
|
|
|
|
#ADJUST SETTINGS FOR MEDIA ITEM
|
|
echo "Configuring Media Item..."
|
|
if (Test-Path -LiteralPath $CustomSettings) {
|
|
Remove-Item -LiteralPath $CustomSettings -Force
|
|
}
|
|
Copy-Item "$LocalDS\Control\CustomSettings.ini" -Destination $CustomSettings | out-null
|
|
((Get-Content -Path $CustomSettings) -replace 'SkipComputerName=.+$','SkipComputerName=NO') | Set-Content -Path $CustomSettings
|
|
(Get-Content -Path $CustomSettings | Where-Object {$_ -notmatch 'WSUSServer'}) | Set-Content -Path $CustomSettings
|
|
(Get-Content -Path $CustomSettings | Where-Object {$_ -notmatch 'EventService'}) | Set-Content -Path $CustomSettings
|
|
Add-Content -Path $CustomSettings -Value 'SkipApplications=YES'
|
|
|
|
#GENERATE ISO
|
|
echo 'Generating bootable ISO file...'
|
|
Update-MDTMedia -path 'DS_USB:\Media\MEDIA001' | out-null
|
|
move-Item -Path "$MediaPath\$ISOName" -Destination "$PSScriptRoot\$ISOName"
|
|
echo 'Done! ISO File is available at $PSScriptRoot\$ISOName'
|
|
echo 'Now use Rufus to flash the ISO to a USB drive with the following settings'
|
|
echo 'Image option: Standard windows installation'
|
|
echo 'Partition scheme: GPT'
|
|
echo 'Target system: UEFI (non CSM)'
|
|
echo 'File system: NTFS'
|
|
echo 'Cluster Size: 4069 bytes'
|
|
echo 'Ignore all other settings.'
|
|
|
|
Read-Host -Prompt "Press Enter to exit"
|