【发布时间】:2018-10-23 23:05:22
【问题描述】:
我正在尝试使用 invoke-vmscript 来修改我们所有服务器上的 IPV4 参数,使用它们的 MAC 地址。
$vms = import-csv C:\temp\adapter_vm.csv -Delimiter ";"
foreach($vm in $vms){
$serveur = $vm.name
$mac = $vm.macaddress
$dns = "$interfaceindex = get-netadapter | where-object MacAddress -Like $($mac) | select-object InterfaceIndex; set-dnsclient -InterfaceIndex $interfaceindex.InterfaceIndex -UseSuffixWhenRegistering $true -RegisterThisConnectionsAddress $true -ConnectionSpecificSuffix test"
Invoke-VMScript -VM $serveur -ScriptType Powershell -ScriptText $dns -GuestUser secret -GuestPassword secret
}
我的问题是远程计算机无法识别 $interfaceindex。
set-dnsclient 需要 interfaceindex,这就是我使用 $interfaceindex 的原因。
你能帮我吗?
也许还有其他方法?
谢谢!
----------------------------------------------------------------------------------------
= : 术语“=”未被识别为 cmdlet、函数、脚本的名称 文件或可运行的程序。检查名称的拼写,或者路径是否 包括,验证路径是否正确,然后重试。 在行:1 字符:5 + & { = 获取网络适配器 | where-object MacAddress -Like 00-50-56-a1-33-61 | 选择- ... + ~ + CategoryInfo : ObjectNotFound: (=:String) [], CommandNotFoundEx 感觉 + FullyQualifiedErrorId : CommandNotFoundException
Set-DnsClient : 无法处理参数的参数转换 '接口索引'。无法将值“.InterfaceIndex”转换为类型 “System.UInt32[]”。错误:“无法将值“.InterfaceIndex”转换为类型 “System.UInt32”。错误:“输入字符串的格式不正确。”” 在行:1 字符:134 + ... InterfaceIndex .InterfaceIndex -UseSuffixWhenRegistering False -RegisterThisConn ... +~~~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Set-DnsClient], ParameterBindi ngArgumentTransformationException + FullyQualifiedErrorId : ParameterArgumentTransformationError,Set-DnsClie nt
【问题讨论】:
-
尝试在最初的
$符号前添加一个反引号。 -
我刚试过,还是不行。错误如下:Set-DnsClient:缺少参数“InterfaceIndex”的参数。指定“System.UInt32[]”类型的参数,然后重试。在 line:1 char:133 + ... set-dnsclient -InterfaceIndex -UseSuffixWhenRegistering True -RegisterThisConn ... + ~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [设置-DnsClient], ParameterB indingException + FullyQualifiedErrorId : MissingArgument,Set-DnsClient –
-
您是否尝试将文本放入文件并将文件作为脚本文本传递?或者可能将 $dns 行从双引号更改为单引号。因为它正在尝试将变量转换为 DNS 字符串输入的变量。
-
@RobertCotterman 我已经尝试使用单引号,但在这种情况下我的 $mac 是空的。
标签: powershell invoke