Network disable script

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
A. Hohl
Posts: 18
Last visit: Thu Aug 01, 2019 3:13 am

Network disable script

Post by A. Hohl »

Windows 7 32 and 64 bit Powershell version 3.0

I am looking for a script that I can remotely disable wireless adapters. here is what I currently have, however I get an error that a null value cannot be called. This is part of a malware response, we disable the Ethernet port but we need a way to disable the wireless and this is what I think we need to do. I just need it to disable wireless only.

$ComputerName = read-host -Prompt "Please Enter the Computer Name to Disable the Wireless Adapter"
$Variable = Get-WmiObject Win32_networkadapter -ComputerName $ComputerName | where {$_.name -like "*wi*"} $Variable.disable() -ErrorAction SilentlyContinue
$variable = Get-WmiObject Win32_networkadapter -ComputerName $ComputerName | where {$_.name -like "*802*"} $Variable.disable() -ErrorAction SilentlyContinue
$variable = Get-WmiObject Win32_networkadapter -ComputerName $ComputerName | where {$_.name -like "*4G*"} $Variable.disable() -ErrorAction SilentlyContinue

IF this script would not work something similar would be great!

Thanks for any help!
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Network disable script

Post by jvierra »

NETSH is the easiest way to do this.
  1. Get-WmiObject Win32_networkadapter -Filter 'Name LIKE "%wi%" OR Name LIKE "%802%"' |
  2.     ForEach-Object{$_.Disable()}
User avatar
A. Hohl
Posts: 18
Last visit: Thu Aug 01, 2019 3:13 am

Re: Network disable script

Post by A. Hohl »

jvierra wrote:NETSH is the easiest way to do this.
  1. Get-WmiObject Win32_networkadapter -Filter 'Name LIKE "%wi%" OR Name LIKE "%802%"' |
  2.     ForEach-Object{$_.Disable()}
Thank you for your quick response... I still have an issue calling this command also... I am getting an error that I cannot call a null value and Invalid query.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Network disable script

Post by jvierra »

You have to post the complete error message.
User avatar
A. Hohl
Posts: 18
Last visit: Thu Aug 01, 2019 3:13 am

Re: Network disable script

Post by A. Hohl »

I apologize, I missed the pipe and put the disable on another line. This script is working great! Thank you for looking into this so quickly.
This topic is 6 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked