2016-08-24 141 views
0

请让我知道如何通过ip地址,子网掩码,网关,而脚本如何参数传递到netsh命令

下面的执行脚本:

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

我曾尝试下面的方法实现却得到了一个错误信息为无效参数

$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' 

回答

0

尝试逃脱双引号(`"),这样就可以在〜应变开始使用它们G。

$VMNetworkSettings="netsh interface ip set address `"Ethernet0`" static $Ip $sub $gateway"