Using Powershell to add iSCSI Targetname and IP from CSV file..

Welcome Forums General PowerShell Q&A Using Powershell to add iSCSI Targetname and IP from CSV file..

This topic contains 1 reply, has 2 voices, and was last updated by

 
Participant
1 week ago.

  • Author
    Posts
  • #182388

    Participant
    Topics: 1
    Replies: 0
    Points: 11
    Rank: Member

    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

  • #182568

    Participant
    Topics: 0
    Replies: 8
    Points: 54
    Rank: Member

    Try this:

    $ipa = $csvFile | Where {"iSCSI1","iSCSI2" -contains $_.VMK} | %{ "IPAddress:{0}" -f $_.IP}

You must be logged in to reply to this topic.