Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update forget command to include SSID #648

Merged
merged 1 commit into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#### Name

Windows - Forget RADIUS WiFi Network | v2.0 JCCG

Windows - Forget RADIUS WiFi Network | v2.0.1 JCCG

#### commandType

Expand Down Expand Up @@ -140,7 +139,7 @@ function Distribute-JCScheduledTask {
</Settings>
<Triggers>
<EventTrigger>
<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>
<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)]] and *[EventData[Data[@Name='SSID']="$RadiusSSID"]]&lt;/Select&gt;&lt;/Query&gt;&lt;/QueryList&gt;</Subscription>
</EventTrigger>
</Triggers>
<Actions Context="Author">
Expand Down Expand Up @@ -187,10 +186,10 @@ The purpose of this script is to resolve an issue when a user changes their Jump

In 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


#### *Import This Command*
#### _Import This Command_

To import this command into your JumpCloud tenant run the below command using the [JumpCloud PowerShell Module](https://github.com/TheJumpCloud/support/wiki/Installing-the-JumpCloud-PowerShell-Module)

```
Import-JCCommand -URL "https://github.com/TheJumpCloud/support/blob/master/PowerShell/JumpCloud%20Commands%20Gallery/Windows%20Commands/Windows%20-%20Forget%20RADIUS%20WiFi%20Network.md"
Import-JCCommand -URL "https://github.com/TheJumpCloud/support/blob/master/PowerShell/JumpCloud%20Commands%20Gallery/Windows%20Commands/Windows%20-%20Forget%20RADIUS%20WiFi%20Network.md"
```
4 changes: 2 additions & 2 deletions PowerShell/JumpCloud Commands Gallery/commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,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 | v2.0 JCCG",
"name": "Windows - Forget RADIUS WiFi Network | v2.0.1 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 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>-NonInteractive -WindowStyle Hidden -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 -Force\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 -Force\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)]] and *[EventData[Data[@Name='SSID']=\"$RadiusSSID\"]]&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>-NonInteractive -WindowStyle Hidden -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 -Force\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 -Force\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