Network Adapter Disable

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 10 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 Adapter Disable

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!
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Network Adapter Disable

Post by davidc »

For scripting related questions, please post in the Windows PowerShell forum:

viewforum.php?f=18
David
SAPIEN Technologies, Inc.
User avatar
A. Hohl
Posts: 18
Last visit: Thu Aug 01, 2019 3:13 am

Re: Network Adapter Disable

Post by A. Hohl »

A. Hohl wrote: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!
User avatar
Alexander Riedel
Posts: 8488
Last visit: Tue Apr 16, 2024 8:42 am
Answers: 20
Been upvoted: 37 times

Re: Network Adapter Disable

Post by Alexander Riedel »

[Topic moved by moderator]
Alexander Riedel
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Network Adapter Disable

Post by jvierra »

The correct syntax would be like this:
  1. if($adapters = Get-WmiObject Win32_networkadapter -FIlter 'name like "%wi%"' -ComputerName $ComputerName){
  2.     foreach($adapter in $adapters){
  3.         Write-Host Disabling $adapter.Name -fore green
  4.         $adapter.disable()
  5.     }
  6. }else{
  7.     Write-Host 'Adapter not found'
  8. }
User avatar
MarvelManiac
Posts: 63
Last visit: Thu Sep 13, 2018 3:40 pm

Re: Network Adapter Disable

Post by MarvelManiac »

jvierra wrote:The correct syntax would be like this:
  1. if($adapters = Get-WmiObject Win32_networkadapter -FIlter 'name like "%wi%"' -ComputerName $ComputerName){
  2.     foreach($adapter in $adapters){
  3.         Write-Host Disabling $adapter.Name -fore green
  4.         $adapter.disable()
  5.     }
  6. }else{
  7.     Write-Host 'Adapter not found'
  8. }

Why is the % sign the proper syntax?
This topic is 6 years and 10 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