January 7, 2016 at 5:48 pm
Hi I have a requirement to disable NIC using powershell remotely. I'm using below command. It works when i hardcode NIC's Name in the command but it is failing when i pass the NIC's Name in variable.
Working Fine: Invoke-Command -Computer MYREMOTESERVER {(Disable-NetAdapter –Name "Trunk1" –Confirm:$false)}
Failing: Invoke-Command -Computer MYREMOTESERVER {(Disable-NetAdapter –Name $NICName –Confirm:$false)}
January 7, 2016 at 7:23 pm
You will want to use the "-args" parameter for Invoke-Command.
Invoke-Command -Computer MYREMOTESERVER {Disable-NetAdapter –Name $NICName –Confirm:$false}
Would become
Invoke-Command -Computer MyRemoteServer { Disable-NetAdapter -Name $NICName -Confirm:$false } -Args $nic
The parameter name you pass does not matter that much as long as you only have one parameter. If you for some reason need to pass multiple, maybe for passing the $false or $true you could do it as this I think:
Invoke-Command -Computer MyRemoteServer { Disable-NetAdapter -Name $args[0] -Confirm:$args[1] } -Args $nic,$true
Pretty sure that should work...
Shawn Melton
Twitter: @wsmelton
Blog: wsmelton.github.com
Github: wsmelton
January 8, 2016 at 1:31 pm
Mac1986 (1/7/2016)
Hi I have a requirement to disable NIC using powershell remotely. I'm using below command. It works when i hardcode NIC's Name in the command but it is failing when i pass the NIC's Name in variable.Working Fine:
Invoke-Command -Computer MYREMOTESERVER {(Disable-NetAdapter –Name "Trunk1" –Confirm:$false)}
Failing:
Invoke-Command -Computer MYREMOTESERVER {(Disable-NetAdapter –Name $NICName –Confirm:$false)}
Very curious... why would someone want to do this? What is the requirement that makes this a requirement?
--Jeff Moden
Change is inevitable... Change for the better is not.
January 8, 2016 at 2:33 pm
It is still failing with same error Cannot validate argument on parameter 'Name'. The argument is null. Provide a valid value for the argument, and then try running the command again.
I've used below 2 commands.
Invoke-Command -Computer MyRemoteServer { Disable-NetAdapter -Name $NICName -Confirm:$false } -Args $nic
Invoke-Command -Computer MyRemoteServer { Disable-NetAdapter -Name $args[0] -Confirm:$args[1] } -Args $nic,$true
January 8, 2016 at 2:35 pm
I might be the dummest person and i'm sure it might wront to recycle NICs one at a time at 15 hour interval. I'm seeing that IPV6 is slowing down and recycling NICs is getting me back the normal latency.
January 8, 2016 at 5:47 pm
Mac1986 (1/8/2016)
I might be the dummest person and i'm sure it might wront to recycle NICs one at a time at 15 hour interval. I'm seeing that IPV6 is slowing down and recycling NICs is getting me back the normal latency.
Cool. Never heard of someone trying to automate such a thing.
Of course, that also means that the reason why we haven't heard of it is because it might be a really bad idea (and I do mean "might" because I don't actually know for sure but seems like it). I'll also say that all sounds like a symptom of a larger problem. For example, I've seen it where a simple switch setting like "auto negotiate" on a local router and/or the NICs themselves can cause huge problems that appear to "build up" over time.
Something else is going on, here, Mac. You should find a good hardware/network forum and dig into it because I think changing the band aid on a stab wound every night isn't the right thing to do.
--Jeff Moden
Change is inevitable... Change for the better is not.
January 10, 2016 at 1:29 am
Mac1986 (1/8/2016)
I might be the dummest person and i'm sure it might wront to recycle NICs one at a time at 15 hour interval. I'm seeing that IPV6 is slowing down and recycling NICs is getting me back the normal latency.
Quick question, are you using IP6 on that server? If not, disable it!
😎
January 10, 2016 at 1:35 am
Jeff Moden (1/8/2016)
Never heard of someone trying to automate such a thing.
Don't think automating this is a good idea and especially on a remote server, anything goes wrong and it's dead in the water.
😎
January 10, 2016 at 8:39 am
Eirikur Eiriksson (1/10/2016)
Jeff Moden (1/8/2016)
Never heard of someone trying to automate such a thing.Don't think automating this is a good idea and especially on a remote server, anything goes wrong and it's dead in the water.
😎
Agreed... like I said in my previous post... "Of course, that also means that the reason why we haven't heard of it is because it might be a really bad idea"
--Jeff Moden
Change is inevitable... Change for the better is not.
January 13, 2016 at 3:21 pm
Hello Shawn,
can you please help me figure out the answer to disable NIC using "-args"
$NICName = 'Trunk1'
Invoke-Command -Computer MyRemoteServer { Disable-NetAdapter -Name $NICName -Confirm:$false } -Args $nic
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply