Array and IPAddress

Hi,

I try to get the IPAddress of a list of computer with this script :

$ListSrv = (Get-Content "C:\Users\admin\Downloads\ListSrv.txt")
ForEach ($srv in $ListSrv){
#Création de la session distante avec le serveur
$s = New-PSSession -ComputerName $srv 

#Declaration des variables aux deux Serveurs
Invoke-Command -Session $s {$Target = "10.10.10.100"}

Invoke-Command -Session $s {
$ip1 = (Get-NetIPAddress | Where-Object {$_.InterfaceAlias -eq "iSCSI-1"}) 
$ip1a = $ip1.IPAddress
$ip2 = (Get-NetIPAddress | Where-Object {$_.InterfaceAlias -eq "iSCSI-2"})
$ip2a = $ip2.IPAddress
$iSCSITab = @("$ip1a","$ip2a")
Write-Host "Tableau IP : $iSCSITab"
Write-Host "Tab: $iSCSITab[0]"
    }
    Write-Host "Nom du Serveur : $srv"
}

But when i execute the script i have this result :

Tableau IP : 10.10.10.10 10.10.10.30
Tab: 10.10.10.10 10.10.10.30[0]
Nom du Serveur : HyperV1
Tableau IP : 10.10.10.20 10.10.10.40
Tab: 10.10.10.20 10.10.10.40[0]
Nom du Serveur : HyperV2

Normally the result should be
Tableau IP : 10.10.10.10 10.10.10.30
Tab : 10.10.10.10

How can i do ?

Thx for replay :wink:

Looks like a problem with the string interpollation. It should be:

Write-Host "Tab: $($iSCSITab[0])"

lol !!!

Ok thx a lot now i have another problmes …
Trys to do by myself and if i don’t success, i will come back here :wink:

$ListSrv = (Get-Content "C:\Users\admin\Downloads\ListSrv.txt")

ForEach ($srv in $ListSrv)
{
  #Création de la session distante avec le serveur
  $s = New-PSSession -ComputerName $srv 

  Write-Host "######################## Session sur $srv ################################"

  Invoke-Command -Session $s
  {
    #Declaration des variables aux deux Serveurs
    $Target = "10.10.10.100"
    $ip1 = (Get-NetIPAddress | Where-Object {$_.InterfaceAlias -eq "iSCSI-1"}) 
    $ip1a = $ip1.IPAddress
    $ip2 = (Get-NetIPAddress | Where-Object {$_.InterfaceAlias -eq "iSCSI-2"})
    $ip2a = $ip2.IPAddress
    $iSCSITab = @("$ip1a","$ip2a")

    #Configuration iSCSI & MPIO
    Foreach ($Cible in $iSCSITab)
    {
      New-IscsiTargetPortal -TargetPortalAddress $Target -TargetPortalPortNumber 3260 -InitiatorPortalAddress $Cible
    }
 
    New-MSDSMSupportedHW -VendorId MSFT2018 -ProductId iSCSIBusType

    Foreach ($Cible in $iSCSITab)
    {
      Get-IscsiTarget | Connect-IscsiTarget -IsMultipathEnabled $true -TargetPortalAddress $Target -InitiatorPortalAddress $Cible -IsPersistent $true
    }

    #Configuration du MPIO en Load Balancing
    Set-MSDSMGlobalDefaultLoadBalancePolicy -Policy FOO
  }
}

Invoke-Command : Le jeu de paramètres ne peut pas être résolu à l’aide des paramètres nommés spécifiés.
Au caractère C:\Users\admin\Documents\Conf-iSCSI-MPIO-SessionDist.ps1:10 : 3

  • Invoke-Command -Session $s
  • + CategoryInfo          : InvalidArgument : (:) [Invoke-Command], ParameterBindingException
    + FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeCommandCommand
    

Ok i have found !!
sry for the post.

It was a syntax error :

$ListSrv = (Get-Content "C:\Users\admin\Downloads\ListSrv.txt")

ForEach ($srv in $ListSrv) {
  #Création de la session distante avec le serveur
  $s = New-PSSession -ComputerName $srv 

  Write-Host "######################## Session sur $srv ################################"

  Invoke-Command -Session $s  {
    #Declaration des variables aux deux Serveurs
    $Target = "10.10.10.100"
    $ip1 = (Get-NetIPAddress | Where-Object {$_.InterfaceAlias -eq "iSCSI-1"}) 
    $ip1a = $ip1.IPAddress
    $ip2 = (Get-NetIPAddress | Where-Object {$_.InterfaceAlias -eq "iSCSI-2"})
    $ip2a = $ip2.IPAddress
    $iSCSITab = @("$ip1a","$ip2a")

    #Configuration iSCSI & MPIO
    Foreach ($Cible in $iSCSITab) {
      New-IscsiTargetPortal -TargetPortalAddress $Target -TargetPortalPortNumber 3260 -InitiatorPortalAddress $Cible
    }
 
    New-MSDSMSupportedHW -VendorId MSFT2018 -ProductId iSCSIBusType

    Foreach ($Cible in $iSCSITab) {
      Get-IscsiTarget | Connect-IscsiTarget -IsMultipathEnabled $true -TargetPortalAddress $Target -InitiatorPortalAddress $Cible -IsPersistent $true
    }

    #Configuration du MPIO en Load Balancing
    Set-MSDSMGlobalDefaultLoadBalancePolicy -Policy FOO
  }
}

Now it’s ok ^^
the “{” wasn’t at the good place :wink:

Thx.