Skip to content

Commit 672a95d

Browse files
committed
[PE Helper] Improve WDS Helper Server Component (client coming soon)
1 parent c1dadd8 commit 672a95d

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Helpers/extps1/PE_Helper/pxehelpers/wds/wdshelper_server.ps1

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ if (((Get-WindowsRole -RoleName "WDS") -eq $false) -or ((Get-WindowsRole -RoleNa
9191
return $false
9292
}
9393

94+
Write-LogMessage -message "Checking share locations..."
95+
$wdsShareLocation = ""
96+
$wdsShareLocation = (Get-ItemPropertyValue -Path "HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Shares" -Name "REMINST" -ErrorAction SilentlyContinue)[3].Replace("Path=", "")
97+
9498
Write-LogMessage -message "Starting Windows Deployment Services Web API..."
9599
Write-LogMessage -message "Server Options:"
96100
Write-LogMessage -message " - Web API Host: $webHost"
@@ -182,6 +186,14 @@ function Deploy-WimImage {
182186
if ($wdsUtilProc.ExitCode -ne 0) {
183187
throw "WDSUtil Exited with Code $($wdsUtilProc.ExitCode)"
184188
}
189+
if (Test-Path -Path "$wdsShareLocation\Images\$($ImageGroup)\$([IO.Path]::GetFileNameWithoutExtension("$ImageName"))\Unattend\ImageUnattend.xml" -PathType Leaf) {
190+
Write-Progress -Activity "WDS Deployment Preparation Work" -Status "Copying answer file..." -PercentComplete 80
191+
try {
192+
Copy-Item -Path "$wdsShareLocation\Images\$($ImageGroup)\$([IO.Path]::GetFileNameWithoutExtension("$ImageName"))\Unattend\ImageUnattend.xml" -Destination "$tmpImageFolderPath\unattend.xml"
193+
} catch {
194+
Write-LogMessage "Could not copy unattended answer file. The target installation will not be unattended"
195+
}
196+
}
185197
Write-Progress -Activity "WDS Deployment Preparation Work" -Status "Finishing up..." -PercentComplete 90
186198
$authInfo = [WdsShareAuthenticationInfo]::new("$env:COMPUTERNAME", "$env:USERNAME", "\\$env:COMPUTERNAME\$shareName")
187199
Write-Progress -Activity "WDS Deployment Preparation Work" -Completed
@@ -193,7 +205,7 @@ function Deploy-WimImage {
193205
}
194206

195207
function Clear-Files {
196-
Get-SmbShare -Name "$shareName" | Remove-SmbShare -Force
208+
Get-SmbShare -Name "$shareName" -ErrorAction SilentlyContinue | Remove-SmbShare -Force -ErrorAction SilentlyContinue
197209
Remove-Item -Path "$tmpImageFolderPath" -Recurse -Force -Verbose -ErrorAction SilentlyContinue
198210
}
199211

0 commit comments

Comments
 (0)