Powershell-如何为数组变量传递两个值

问题描述 投票:0回答:1

Msvm_GuestNetworkAdapterConfiguration类接受字符串数组中的DNSServers

https://docs.microsoft.com/en-us/windows/win32/hyperv_v2/msvm-guestnetworkadapterconfiguration

我有要在CSV中填充的数据

Set-VMNetworkConfiguration -IPAddress $sipaddress -Subnet $netmask -DNSServers $dns -DefaultGateway $gateway

如何将从CSV读取的两个变量传递到命令上的变量DNSServers?

模块Set-VMNetworkConfiguration接受值为

    [Parameter(Mandatory=$false,
  Position=4,
  ParameterSetName='Static')]
 [String[]]$DNSServers = @(),

要通过的样本

site,ipaddress,netmask,gateway,dns1,dns2
1234,172.28.158.122,255.255.255.240,172.28.158.113,172.28.158.113,172.28.158.113
5678,172.28.158.123,255.255.255.240,172.28.158.113,172.28.158.113,172.28.158.113
F06E,172.28.158.124,255.255.255.240,172.28.158.113,172.28.158.113,172.28,158.113

下面的并置为

$dns = $($dns1[$index],$dns2[$index])

传递变量状态

DEBUG:    1+  >>>> Get-VMNetworkAdapter -VMName packer-centos8-base-g2-1 | Set-VMNetworkConfiguration -IPAddress 172.28.158.124 -Subnet 255.255.255.240 -DNSServers 172.28.158.113 172.28.158.113 -DefaultGateway 172.28.158.113

最终出现错误提示

Cannot process argument transformation on parameter 'NetworkAdapter'. Cannot convert the "172.28.158.113" value of type "System.String" to type "Microsoft.HyperV.PowerShell.VMNetworkAdapter".

pls指南

arrays powershell hyper-v
1个回答
0
投票
您有语法错误。
© www.soinside.com 2019 - 2024. All rights reserved.