user245862
user245862

Reputation: 19

Disable NetworkAdapter CMD

How can I run this powershell script in cmd?

$adaptor = Get-WmiObject -Class Win32_NetworkAdapter | Where-Object {$_.Name -like "*Wireless*"}
$adaptor.Disable()

Upvotes: 0

Views: 150

Answers (2)

Shay Levy
Shay Levy

Reputation: 126712

Make sure CMD is elevated. You could use WMIC directly from CMD:

wmic nic where "NetConnectionID like '%wireless%'" call disable

Upvotes: 2

Scott Chamberlain
Scott Chamberlain

Reputation: 127543

you can pass commands to the powershell executeable via the -Command switch and prefixing the script block with &.

powershell -Command "& { $adaptor = Get-WmiObject -Class Win32_NetworkAdapter | Where-Object {$_.Name -like "*Wireless*"}; $adaptor.Disable() }"

You can read more by running the command powershell -?

Upvotes: 1

Related Questions