Need Batch or PowerShell script

TechUST 601 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 Security Intune Other
Microsoft System Center Other
{count} votes

2 answers

Sort by: Most helpful
  1. AlexZhu-MSFT 6,591 Reputation points Moderator
    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 6,591 Reputation points Moderator
    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


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.