I have the following script which retrieves IP addresses from a CSV file but does not add them to the -InitiatorId.
$csvFile = Import-CSV -Path C:\Users\Administrator\Desktop\esxiHostsDeployment.csv foreach ($NFSRow in $csvFile) { $virtualSwitch = $NFSRow.Switch $vmK = $NFSRow.VMK $ipa = $csvFile | Where {“iSCSI1″,”iSCSI2″ -contains $_.VMK} | Select -Property @{N=”IPAddress:”;E={$_.IP}} }
When I check the variable value with $ipa I get :
IPAddress: ———- 192.168.4.24 192.168.4.25 192.168.4.34 192.168.4.35
If I use write-host $ipa I get
write-host $ipa @{IPAddress:=192.168.4.24} @{IPAddress:=192.168.4.25} @{IPAddress:=192.168.4.34} @{IPAddress:=192.168.4.35}
And when this is passed to the -InitiatorId I get the following error:
Set-IscsiServerTarget : Cannot bind parameter 'InitiatorIds'. Cannot convert the “@{IPAddress:=192.168.4.24}” value of type “Selected.System.Management.Automation.PSCustomObject” to type “Microsoft.Iscsi.Target.Commands.InitiatorId”. At line:1 char:61 + Set-IscsiServerTarget -TargetName “esxiHosts1” -InitiatorId $ipa + ~~~~ + CategoryInfo : InvalidArgument: (:) [Set-IscsiServerTarget], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Iscsi.Target.Commands.SetIscsiServerTargetCommand
Any suggestions how I can get the results in the format : IPAddress:192.168.4.24, IPAddress:192.168.4.25 in the results.
Thank You