0

I am tring to change the IP address with netsh within a script. I get the error: "parameter is incorrect" This is the script:

$ManagmentAddress = '192.168.11.130'
Invoke-Command -ComputerName $OldName -ScriptBlock {netsh interface ip set address "Ethernet0" static $ManagmentAddress 255.255.0.0 } -Credential $Creds

If I change the command to use actual value instead of the argument like this:

Invoke-Command -ComputerName $OldName -ScriptBlock {netsh interface ip set address "Ethernet0" static 192.168.11.130 255.255.0.0 } -Credential $Creds

It works.

1 Answer 1

1

You are missing param() block for ScripBlock with corresponding -ArgumentList value.

$ManagmentAddress = '192.168.11.130'
Invoke-Command -ComputerName $OldName -ScriptBlock {param($ManagmentAddress) netsh interface ip set address "Ethernet0" static $ManagmentAddress 255.255.0.0 } -Credential $Creds -ArgumentList $ManagmentAddress
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.