Skip to content

Commit

Permalink
Forget RADIUS WiFi Network v2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gweinjc committed Nov 13, 2024
1 parent 6fe9fd3 commit 6fe2efd
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#### Name

Windows - Forget RADIUS WiFi Network | v1.0 JCCG
Windows - Forget RADIUS WiFi Network | v2.0 JCCG


#### commandType
Expand Down Expand Up @@ -34,7 +34,6 @@ function Get-WifiProfile {
Foreach (`$WLANProfile in `$Name) {
`$ProfileList | Where-Object { `$_.Name -match `$WLANProfile }
}
}
End {
If (`$Name -eq `$NULL) {
Expand All @@ -60,8 +59,64 @@ function Remove-WifiProfile {
}
}
}
function Show-WiFiReconnectForm {
param
(
[System.Array]`$Name = `$NULL
)
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
`$form = New-Object System.Windows.Forms.Form
`$form.Text = 'JumpCloud Radius'
`$form.Size = New-Object System.Drawing.Size(300,150)
`$form.StartPosition = 'CenterScreen'
`$okButton = New-Object System.Windows.Forms.Button
`$okButton.Location = New-Object System.Drawing.Point(75,75)
`$okButton.Size = New-Object System.Drawing.Size(75,23)
`$okButton.Text = 'OK'
`$okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
`$form.AcceptButton = `$okButton
`$form.Controls.Add(`$okButton)
`$cancelButton = New-Object System.Windows.Forms.Button
`$cancelButton.Location = New-Object System.Drawing.Point(150,75)
`$cancelButton.Size = New-Object System.Drawing.Size(75,23)
`$cancelButton.Text = 'Cancel'
`$cancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
`$form.CancelButton = `$cancelButton
`$form.Controls.Add(`$cancelButton)
`$label = New-Object System.Windows.Forms.Label
`$label.Location = New-Object System.Drawing.Point(10,20)
`$label.Size = New-Object System.Drawing.Size(280,50)
`$label.Text = "Please reconnect to the `$Name network with your updated credentials"
`$form.Controls.Add(`$label)
if (`$PSVersionTable.PSVersion.Major -gt 5) {
`$iconBase64 = [Convert]::ToBase64String((Get-Content "C:\Program Files\JumpCloudTray\TrayIconLight.ico" -AsByteStream))
`$iconBytes = [Convert]::FromBase64String(`$iconBase64)
# initialize a Memory stream holding the bytes
`$stream = [System.IO.MemoryStream]::new(`$iconBytes, 0, `$iconBytes.Length)
`$Form.Icon = [System.Drawing.Icon]::FromHandle(([System.Drawing.Bitmap]::new(`$stream).GetHIcon()))
} else {
# PowerShell versions older than 5.0 use this:
`$iconBase64 = [Convert]::ToBase64String((Get-Content "C:\Program Files\JumpCloudTray\TrayIconLight.ico" -Encoding Byte))
`$iconBytes = [Convert]::FromBase64String(`$iconBase64)
`$stream = New-Object IO.MemoryStream(`$iconBytes, 0, `$iconBytes.Length)
`$Form.Icon = [System.Drawing.Icon]::FromHandle((New-Object System.Drawing.Bitmap -Argument `$stream).GetHIcon())
}
`$form.Topmost = `$true
`$form.FormBorderStyle = 'FixedDialog'
`$RadiusForm = `$form.ShowDialog()
if (`$RadiusForm -eq [System.Windows.Forms.DialogResult]::OK) {
explorer ms-availablenetworks:
# when done, dispose of the stream and form
`$stream.Dispose()
`$Form.Dispose()
} else {
`$stream.Dispose()
`$Form.Dispose()
}
}
Remove-WifiProfile "$($RadiusSSID)"
Show-WiFiReconnectForm "$($RadiusSSID)"
"@
function Distribute-JCScheduledTask {
param (
Expand Down
4 changes: 2 additions & 2 deletions PowerShell/JumpCloud Commands Gallery/commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,9 @@
"description": "This command will remove the jumpcloud-agent.exe from Windows Defender scheduled and real-time scanning.\n\nThe command Add-MpPreference is only available in the 64-bit environment and the JumpCloud agent operates in the 32-bit environment which is why sysnative is used."
},
{
"name": "Windows - Forget RADIUS WiFi Network | v1.0 JCCG",
"name": "Windows - Forget RADIUS WiFi Network | v2.0 JCCG",
"type": "windows",
"command": "# Enter the SSID of the Radius network\n$RadiusSSID = ''\n\n# Change Overwrite to $true if you would like to re-create existing Scheduled Tasks\n# This should only be used if redistributing this command to devices\n$Overwrite = $false\n\n\n# DO NOT EDIT BELOW THIS LINE #\n$removeWifips1 = @\"\nfunction Get-WifiProfile {\n [cmdletbinding()]\n param\n (\n [System.Array]`$Name = `$NULL\n )\n Begin {\n `$list = ((netsh.exe wlan show profiles) -match '\\s{2,}:\\s') -replace '.*:\\s' , ''\n `$ProfileList = `$List | Foreach-object { [pscustomobject]@{Name = `$_ } }\n }\n Process {\n Foreach (`$WLANProfile in `$Name) {\n `$ProfileList | Where-Object { `$_.Name -match `$WLANProfile }\n }\n\n }\n End {\n If (`$Name -eq `$NULL) {\n `$Profilelist\n }\n }\n}\nfunction Remove-WifiProfile {\n [cmdletbinding()]\n param\n (\n [System.Array]`$Name = `$NULL\n )\n begin {}\n process {\n Foreach (`$item in `$Name) {\n `$Result = (netsh.exe wlan delete profile `$item)\n If (`$Result -match 'deleted') {\n \"WifiProfile : `$Item Deleted\"\n } else {\n \"WifiProfile : `$Item NotFound\"\n }\n }\n }\n}\n\nRemove-WifiProfile \"$($RadiusSSID)\"\n\"@\nfunction Distribute-JCScheduledTask {\n param (\n [boolean]$Overwrite\n )\n # Get Current User for JC Commmand\n $CurrentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name\n\n # Scheduled Task XML Configuration\n $ScheduledTaskXML = @\"\n<?xml version=\"1.0\" encoding=\"UTF-16\"?>\n<Task version=\"1.2\" xmlns=\"http://schemas.microsoft.com/windows/2004/02/mit/task\">\n <Settings>\n <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>\n <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>\n <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>\n <IdleSettings>\n <StopOnIdleEnd>true</StopOnIdleEnd>\n <RestartOnIdle>false</RestartOnIdle>\n </IdleSettings>\n </Settings>\n <Triggers>\n <EventTrigger>\n <Subscription>&lt;QueryList&gt;&lt;Query Id=\"0\" Path=\"Microsoft-Windows-WLAN-AutoConfig/Operational\"&gt;&lt;Select Path=\"Microsoft-Windows-WLAN-AutoConfig/Operational\"&gt;*[System[Provider[@Name='Microsoft-Windows-WLAN-AutoConfig'] and Task = 24010 and (EventID=8002)]]&lt;/Select&gt;&lt;/Query&gt;&lt;/QueryList&gt;</Subscription>\n </EventTrigger>\n </Triggers>\n <Actions Context=\"Author\">\n <Exec>\n <Command>\"C:\\Windows\\SysWOW64\\WindowsPowerShell\\v1.0\\powershell.exe\"</Command>\n <Arguments>-ExecutionPolicy ByPass -File \"C:\\scripts\\removeWifi.ps1\"</Arguments>\n </Exec>\n </Actions>\n</Task>\n\"@\n # Check if the scheduled task exists, skip unless Overwrite is specified\n $scheduledTask = Get-ScheduledTask -TaskName \"JumpCloud - Remove WiFi Failure\" -ErrorAction SilentlyContinue\n if ($scheduledTask) {\n Write-Output \"[status] JumpCloud - Remove WiFi Failure scheduled task already exists\"\n if ($Overwrite) {\n # Save the removeWifi.ps1 file to C:\\scripts\\removeWifi.ps1\n if (!(Test-Path -Path C:\\scripts)) {\n New-Item -Path \"C:\\\" -Name \"scripts\" -ItemType \"directory\"\n }\n $removeWifips1 | Out-File -FilePath C:\\scripts\\removeWifi.ps1 -force\n # Overwrite specified, unregister existing task and recreate\n Unregister-ScheduledTask -TaskPath '\\JumpCloud RADIUS\\' -TaskName 'JumpCloud - Remove Wifi Failure' -Confirm:$false\n Write-Output \"[status] Removed existing 'JumpCloud - Remove WiFi Failure' Scheduled Task\"\n Register-ScheduledTask -xml $ScheduledTaskXML -TaskName \"JumpCloud - Remove WiFi Failure\" -TaskPath \"\\JumpCloud RADIUS\\\" -User $CurrentUser \u2013Force\n Write-Output \"[status] Distributed 'JumpCloud - Remove WiFi Failure' Scheduled Task\"\n }\n } else {\n # Save the removeWifi.ps1 file to C:\\scripts\\removeWifi.ps1\n if (!(Test-Path -Path C:\\scripts)) {\n New-Item -Path \"C:\\\" -Name \"scripts\" -ItemType \"directory\"\n }\n $removeWifips1 | Out-File -FilePath C:\\scripts\\removeWifi.ps1\n # Create the Scheduled Task\n Register-ScheduledTask -xml $ScheduledTaskXML -TaskName \"JumpCloud - Remove WiFi Failure\" -TaskPath \"\\JumpCloud RADIUS\\\" -User $CurrentUser \u2013Force\n Write-Output \"[status] Distributed 'JumpCloud - Remove WiFi Failure' Scheduled Task\"\n }\n}\nDistribute-JCScheduledTask -Overwrite $Overwrite",
"command": "# Enter the SSID of the Radius network\n$RadiusSSID = ''\n\n# Change Overwrite to $true if you would like to re-create existing Scheduled Tasks\n# This should only be used if redistributing this command to devices\n$Overwrite = $false\n\n\n# DO NOT EDIT BELOW THIS LINE #\n$removeWifips1 = @\"\nfunction Get-WifiProfile {\n [cmdletbinding()]\n param\n (\n [System.Array]`$Name = `$NULL\n )\n Begin {\n `$list = ((netsh.exe wlan show profiles) -match '\\s{2,}:\\s') -replace '.*:\\s' , ''\n `$ProfileList = `$List | Foreach-object { [pscustomobject]@{Name = `$_ } }\n }\n Process {\n Foreach (`$WLANProfile in `$Name) {\n `$ProfileList | Where-Object { `$_.Name -match `$WLANProfile }\n }\n }\n End {\n If (`$Name -eq `$NULL) {\n `$Profilelist\n }\n }\n}\nfunction Remove-WifiProfile {\n [cmdletbinding()]\n param\n (\n [System.Array]`$Name = `$NULL\n )\n begin {}\n process {\n Foreach (`$item in `$Name) {\n `$Result = (netsh.exe wlan delete profile `$item)\n If (`$Result -match 'deleted') {\n \"WifiProfile : `$Item Deleted\"\n } else {\n \"WifiProfile : `$Item NotFound\"\n }\n }\n }\n}\nfunction Show-WiFiReconnectForm {\n param\n (\n [System.Array]`$Name = `$NULL\n )\n Add-Type -AssemblyName System.Windows.Forms\n Add-Type -AssemblyName System.Drawing\n `$form = New-Object System.Windows.Forms.Form\n `$form.Text = 'JumpCloud Radius'\n `$form.Size = New-Object System.Drawing.Size(300,150)\n `$form.StartPosition = 'CenterScreen'\n `$okButton = New-Object System.Windows.Forms.Button\n `$okButton.Location = New-Object System.Drawing.Point(75,75)\n `$okButton.Size = New-Object System.Drawing.Size(75,23)\n `$okButton.Text = 'OK'\n `$okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK\n `$form.AcceptButton = `$okButton\n `$form.Controls.Add(`$okButton)\n `$cancelButton = New-Object System.Windows.Forms.Button\n `$cancelButton.Location = New-Object System.Drawing.Point(150,75)\n `$cancelButton.Size = New-Object System.Drawing.Size(75,23)\n `$cancelButton.Text = 'Cancel'\n `$cancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel\n `$form.CancelButton = `$cancelButton\n `$form.Controls.Add(`$cancelButton)\n `$label = New-Object System.Windows.Forms.Label\n `$label.Location = New-Object System.Drawing.Point(10,20)\n `$label.Size = New-Object System.Drawing.Size(280,50)\n `$label.Text = \"Please reconnect to the `$Name network with your updated credentials\"\n `$form.Controls.Add(`$label)\n if (`$PSVersionTable.PSVersion.Major -gt 5) {\n `$iconBase64 = [Convert]::ToBase64String((Get-Content \"C:\\Program Files\\JumpCloudTray\\TrayIconLight.ico\" -AsByteStream))\n `$iconBytes = [Convert]::FromBase64String(`$iconBase64)\n # initialize a Memory stream holding the bytes\n `$stream = [System.IO.MemoryStream]::new(`$iconBytes, 0, `$iconBytes.Length)\n `$Form.Icon = [System.Drawing.Icon]::FromHandle(([System.Drawing.Bitmap]::new(`$stream).GetHIcon()))\n } else {\n # PowerShell versions older than 5.0 use this:\n `$iconBase64 = [Convert]::ToBase64String((Get-Content \"C:\\Program Files\\JumpCloudTray\\TrayIconLight.ico\" -Encoding Byte))\n `$iconBytes = [Convert]::FromBase64String(`$iconBase64)\n `$stream = New-Object IO.MemoryStream(`$iconBytes, 0, `$iconBytes.Length)\n `$Form.Icon = [System.Drawing.Icon]::FromHandle((New-Object System.Drawing.Bitmap -Argument `$stream).GetHIcon())\n }\n `$form.Topmost = `$true\n `$form.FormBorderStyle = 'FixedDialog'\n `$RadiusForm = `$form.ShowDialog()\n if (`$RadiusForm -eq [System.Windows.Forms.DialogResult]::OK) {\n explorer ms-availablenetworks:\n # when done, dispose of the stream and form\n `$stream.Dispose()\n `$Form.Dispose()\n } else {\n `$stream.Dispose()\n `$Form.Dispose()\n }\n}\nRemove-WifiProfile \"$($RadiusSSID)\"\nShow-WiFiReconnectForm \"$($RadiusSSID)\"\n\"@\nfunction Distribute-JCScheduledTask {\n param (\n [boolean]$Overwrite\n )\n # Get Current User for JC Commmand\n $CurrentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name\n\n # Scheduled Task XML Configuration\n $ScheduledTaskXML = @\"\n<?xml version=\"1.0\" encoding=\"UTF-16\"?>\n<Task version=\"1.2\" xmlns=\"http://schemas.microsoft.com/windows/2004/02/mit/task\">\n <Settings>\n <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>\n <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>\n <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>\n <IdleSettings>\n <StopOnIdleEnd>true</StopOnIdleEnd>\n <RestartOnIdle>false</RestartOnIdle>\n </IdleSettings>\n </Settings>\n <Triggers>\n <EventTrigger>\n <Subscription>&lt;QueryList&gt;&lt;Query Id=\"0\" Path=\"Microsoft-Windows-WLAN-AutoConfig/Operational\"&gt;&lt;Select Path=\"Microsoft-Windows-WLAN-AutoConfig/Operational\"&gt;*[System[Provider[@Name='Microsoft-Windows-WLAN-AutoConfig'] and Task = 24010 and (EventID=8002)]]&lt;/Select&gt;&lt;/Query&gt;&lt;/QueryList&gt;</Subscription>\n </EventTrigger>\n </Triggers>\n <Actions Context=\"Author\">\n <Exec>\n <Command>\"C:\\Windows\\SysWOW64\\WindowsPowerShell\\v1.0\\powershell.exe\"</Command>\n <Arguments>-ExecutionPolicy ByPass -File \"C:\\scripts\\removeWifi.ps1\"</Arguments>\n </Exec>\n </Actions>\n</Task>\n\"@\n # Check if the scheduled task exists, skip unless Overwrite is specified\n $scheduledTask = Get-ScheduledTask -TaskName \"JumpCloud - Remove WiFi Failure\" -ErrorAction SilentlyContinue\n if ($scheduledTask) {\n Write-Output \"[status] JumpCloud - Remove WiFi Failure scheduled task already exists\"\n if ($Overwrite) {\n # Save the removeWifi.ps1 file to C:\\scripts\\removeWifi.ps1\n if (!(Test-Path -Path C:\\scripts)) {\n New-Item -Path \"C:\\\" -Name \"scripts\" -ItemType \"directory\"\n }\n $removeWifips1 | Out-File -FilePath C:\\scripts\\removeWifi.ps1 -force\n # Overwrite specified, unregister existing task and recreate\n Unregister-ScheduledTask -TaskPath '\\JumpCloud RADIUS\\' -TaskName 'JumpCloud - Remove Wifi Failure' -Confirm:$false\n Write-Output \"[status] Removed existing 'JumpCloud - Remove WiFi Failure' Scheduled Task\"\n Register-ScheduledTask -xml $ScheduledTaskXML -TaskName \"JumpCloud - Remove WiFi Failure\" -TaskPath \"\\JumpCloud RADIUS\\\" -User $CurrentUser \u2013Force\n Write-Output \"[status] Distributed 'JumpCloud - Remove WiFi Failure' Scheduled Task\"\n }\n } else {\n # Save the removeWifi.ps1 file to C:\\scripts\\removeWifi.ps1\n if (!(Test-Path -Path C:\\scripts)) {\n New-Item -Path \"C:\\\" -Name \"scripts\" -ItemType \"directory\"\n }\n $removeWifips1 | Out-File -FilePath C:\\scripts\\removeWifi.ps1\n # Create the Scheduled Task\n Register-ScheduledTask -xml $ScheduledTaskXML -TaskName \"JumpCloud - Remove WiFi Failure\" -TaskPath \"\\JumpCloud RADIUS\\\" -User $CurrentUser \u2013Force\n Write-Output \"[status] Distributed 'JumpCloud - Remove WiFi Failure' Scheduled Task\"\n }\n}\nDistribute-JCScheduledTask -Overwrite $Overwrite",
"link": "https://github.com/TheJumpCloud/support/blob/master/PowerShell/JumpCloud%20Commands%20Gallery/Windows%20Commands/Windows%20-%20Forget%20RADIUS%20WiFi%20Network.md",
"description": "The purpose of this script is to resolve an issue when a user changes their JumpCloud password after connecting to a JumpCloud backed Radius network they will never be able to connect unless they forget the existing network.\n\nIn order to accomplish this, the command will create a scheduled task on the workstation that looks for 8002 errors when attempting to connect to the specified Radius SSID. If an error is detected, a PowerShell script will be initiated that will forget the network for the user which will allow them to attempt to connect again and prompt for their updated credentials"
},
Expand Down

0 comments on commit 6fe2efd

Please sign in to comment.