How to Disable UPnP Automatically Using Powershell Code on Windows 11

155 Views Asked by At

Me and my friend have been trying to automatically disable UPnP using powershell code. Currently, this code is running as a script and is not doing what it claims to be doing. We theorize that the name "NetUPNPGlobalState" may not actually be what we need to use "GET" for. Does anyone know if we are correct in our theory? If so or if not, what steps should we take? Are there any errors that may have slipped us?

# Check if UPnP is enabled
$upnpEnabled = Get-NetUPNPGlobalState

if ($upnpEnabled.Enabled) {
    # Disable UPnP
    Set-NetUPNPGlobalState -Enabled $false
    Write-Host "UPnP has been disabled."
} else {
    Write-Host "UPnP is already disabled."
}

We tried using chatgpt but it was not able to help us. It gave us instructions, but they were incorrect. When we checked to see if the code had done what it claimed, we found that there was no change made.

Here is the error message we received:

Get-NetUPNPGlobalState : The term 'Get-NetUPNPGlobalState' is not recognized as the name of a cmdlet, function, script file, 
or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\Admin\Documents\Codes\Disable UPnP (WIP).ps1:2 char:16
+ $upnpEnabled = Get-NetUPNPGlobalState
+                ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-NetUPNPGlobalState:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
UPnP is already disabled.

If any more information is needed please let me know! Thank you for your help!

0

There are 0 best solutions below