Skip to content

Commit

Permalink
Merge pull request #134 from AkosBakos/WinRE_WiFi
Browse files Browse the repository at this point in the history
Adding unattend function into WinRE
  • Loading branch information
OSDeploy authored Apr 15, 2024
2 parents a1c4f02 + b4b18fc commit c5cfe54
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 74 deletions.
30 changes: 29 additions & 1 deletion Public/OSDCloudSetup/OSDCloudWinPE.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,24 @@

[Switch]
#Will leverage WirelessConnect.EXE instead of the Commandline Tools to connect to WiFi
$WirelessConnect
$WirelessConnect,

[ValidateScript( {
if (Test-Path -Path $_) {
$true
} else {
throw "$_ doesn't exists"
}
if ($_ -notmatch "\.xml$") {
throw "$_ isn't xml file"
}
if (!(([xml](Get-Content $_ -Raw)).WLANProfile.Name) -or (([xml](Get-Content $_ -Raw)).WLANProfile.MSM.security.sharedKey.protected) -ne "false") {
throw "$_ isn't valid Wi-Fi XML profile (is the password correctly in plaintext?). Use command like this, to create it: netsh wlan export profile name=`"MyWifiSSID`" key=clear folder=C:\Wifi"
}
})]
[System.IO.FileInfo]
#Imports and uses a WiFi Profile to connect to WiFi
$WifiProfile
)
#=================================================
# Start the Clock
Expand Down Expand Up @@ -231,11 +248,22 @@
}
#endregion

#region WifiProfile
if ($WifiProfile) {
Write-Host -ForegroundColor DarkGray "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) Adding WiFi Profile $WifiProfile"
Copy-Item -Path $WifiProfile -Destination "$env:TEMP\WiFiProfile.xml" -Force | Out-Null
robocopy "$env:TEMP" "$MountPath\OSDCloud\Config\Scripts" WiFiProfile.xml /ndl /njh /njs /b /np /r:0 /w:0
}
#endregion

#region Default Startnet.cmd
$OSDVersion = (Get-Module -Name OSD -ListAvailable | Sort-Object Version -Descending | Select-Object -First 1).Version
if ($WirelessConnect){
$InitializeOSDCloudStartnetCommand = "Initialize-OSDCloudStartnet -WirelessConnect"
}
elseif ($WifiProfile) {
$InitializeOSDCloudStartnetCommand = "Initialize-OSDCloudStartnet -WifiProfile"
}
else {
$InitializeOSDCloudStartnetCommand = "Initialize-OSDCloudStartnet"
}
Expand Down
17 changes: 14 additions & 3 deletions Public/OSDCloudTS/Initialize-OSDCloudStartnet.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ function Initialize-OSDCloudStartnet {
[CmdletBinding()]
param (
[System.Management.Automation.SwitchParameter]
$WirelessConnect
$WirelessConnect,

[System.Management.Automation.SwitchParameter]
$WifiProfile
)

# Make sure we are in WinPE
Expand Down Expand Up @@ -53,7 +56,7 @@ function Initialize-OSDCloudStartnet {
When Edit-OSDCloudWinPE is executed then these files should be copied to the mounted WinPE
In WinPE, the scripts will exist in X:\OSDCloud\Config\Scripts\*
#>
$Global:ScriptStartNet = Get-PSDrive -PSProvider FileSystem | Where-Object {$_.Name -ne 'C'} | ForEach-Object {
$Global:ScriptStartNet = Get-PSDrive -PSProvider FileSystem | Where-Object { $_.Name -ne 'C' } | ForEach-Object {
Get-ChildItem "$($_.Root)OSDCloud\Config\Scripts\StartNet\" -Include "*.ps1" -File -Recurse -Force -ErrorAction Ignore
}
if ($Global:ScriptStartNet) {
Expand All @@ -68,7 +71,7 @@ function Initialize-OSDCloudStartnet {

# Initialize Splash Screen
# Looks for SPLASH.JSON files in OSDCloud\Config, if found, it will run a splash screen.
$Global:SplashScreen = Get-PSDrive -PSProvider FileSystem | Where-Object {$_.Name -ne 'C'} | ForEach-Object {
$Global:SplashScreen = Get-PSDrive -PSProvider FileSystem | Where-Object { $_.Name -ne 'C' } | ForEach-Object {
Get-ChildItem "$($_.Root)OSDCloud\Config\" -Include "SPLASH.JSON" -File -Recurse -Force -ErrorAction Ignore
}

Expand Down Expand Up @@ -103,6 +106,14 @@ function Initialize-OSDCloudStartnet {
if ($WirelessConnect) {
Start-Process PowerShell -ArgumentList 'Start-WinREWiFi -WirelessConnect' -Wait
}
elseif ($WifiProfile) {
$Global:WifiProfile = Get-PSDrive -PSProvider FileSystem | Where-Object { $_.Name -ne 'C' } | ForEach-Object {
Get-ChildItem "$($_.Root)OSDCloud\Config\Scripts" -Include "WiFiProfile.xml" -File -Recurse -Force -ErrorAction Ignore
}

Write-Host -ForegroundColor DarkGray "$($TimeSpan.ToString("mm':'ss")) Using the WiFi Profile: $($Global:WifiProfile)"
Start-Process PowerShell -ArgumentList "Start-WinREWiFi -WifiProfile `"$Global:WifiProfile`"" -Wait
}
else {
Start-Process PowerShell Start-WinREWiFi -Wait
}
Expand Down
Loading

0 comments on commit c5cfe54

Please sign in to comment.