Need Batch or PowerShell script

TechUST 416 Reputation points
2024-03-20T19:31:46.5666667+00:00

Hi Expert,

I am upgrading the machine to Win11 23H2 in our environment using the in-place upgrade method, but after the upgrade, it's not connecting to the corporate Wi-Fi. I also checked that the machine is patched with the latest month's updates. So now, can you provide a script that forgets the corporate Wi-Fi connection? Ideally, it should be some kind of login script that runs only once when a user logs into Win11 after upgrading. Also, would request please test script in your test environment.

Microsoft System Center
Microsoft System Center
A suite of Microsoft systems management products that offer solutions for managing datacenter resources, private clouds, and client devices.
850 questions
Microsoft Intune
Microsoft Intune
A Microsoft cloud-based management solution that offers mobile device management, mobile application management, and PC management capabilities.
4,456 questions
{count} votes

2 answers

Sort by: Most helpful
  1. AlexZhu-MSFT 5,551 Reputation points Microsoft Vendor
    2024-03-21T01:42:30.0366667+00:00

    Hi,

    Sure, you can clear the wifi profile using .bat or .ps1 through GPO. If we use the batch file, only a single command line is required.

    netsh wlan delete profile name=<wifi_name>
    

    gpo

    editgpo

    strrtup

    script

    Regards,

    Alex

    1 person found this answer helpful.

  2. AlexZhu-MSFT 5,551 Reputation points Microsoft Vendor
    2024-03-21T07:35:11.03+00:00

    Hi TechUST,

    If you prefer the script run only once, you can use the script below:

    $file_result = "c:\even_run.txt" 
    
    if (test-path $file_result) 
        { 
            write-host "$file_result exists. ignored!" 
        } 
    else 
        { 
            $command = 'netsh wlan delete profile name=actual_wifi_name' 
            invoke-expression $command 
            $str1 = "anything you want to put here" 
            add-content -path $file_result -value $str1 
            write-host "wlan profile removed!" 
        } 
    
    

    Regards,

    Alex Zhu