Girish Kumar Mayigowda Girish Kumar Mayigowda - 1 year ago 161
PowerShell Question

How to pass parameter to netsh command

Please let me know how to pass ipaddress,subnetmask,gateway while execution of the script

Below is the script:

$VMNetworkSettings = 'netsh interface ip set address "Ethernet0" static x.x.x.x(ipaddress) x.x.x.x(subnet mask) x.x.x.x(gateway)'

i have tried the below way to achieve but got an error message as invalid parameter

$Ip = Read-Host -Prompt "Enter the ip address"
$sub = Read-Host -Prompt "Enter the subnet"
$gateway = Read-Host -Prompt "Enter the gateway"
$VMNetworkSettings = 'netsh interface ip set address "Ethernet0" static $Ip $sub $gateway'

Answer Source

Try escaping the double quotes (`") so that you can use them at the start of the string.

$VMNetworkSettings="netsh interface ip set address `"Ethernet0`" static $Ip $sub $gateway" 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download