1

I have been breaking my head over this.

what I want is to make a small python program which does utput a list of ipadress with their corresponding NIC

in powershell this is possible by doing this, I have found this script on the internet:

function Get-IscsiPortNumber {
    $PortalSummary = @()
    $portalInfo = get-wmiobject -namespace root\wmi -class msiscsi_portalinfoclass
    $eScriptBlock ={([Net.IPAddress]$_.ipaddr.IPV4Address).IPAddressToString}
    $customLabel = @{Label="IpAddress"; expression = $eScriptBlock}
    foreach ($portal in $portalInfo) {
        foreach ($p in ($portal.portalinformation)) {
            $CurrentPort = New-Object PsObject -Property @{
                Instance = ($portal.instancename).ToUpper()
                Port     = $p.port
                IP       = ([net.ipaddress]$p.ipaddr.IpV4Address).IPAddressToString
            }
            $PortalSummary += $CurrentPort
        }
    }
    return $PortalSummary
}

Get-IscsiPortNumber | ft -AutoSize

This doesnt work with all windows versions though. for instance I get this error message on a windows server 2003 box:

PS C:\Documents and Settings\Administrator\Desktop> .\test.ps1
New-Object : A parameter cannot be found that matches parameter name 'Property'.
At C:\Documents and Settings\Administrator\Desktop\test.ps1:8 char:57
+             $CurrentPort = New-Object PsObject -Property  <<<< @{
New-Object : A parameter cannot be found that matches parameter name 'Property'.
At C:\Documents and Settings\Administrator\Desktop\test.ps1:8 char:57
+             $CurrentPort = New-Object PsObject -Property  <<<< @{
New-Object : A parameter cannot be found that matches parameter name 'Property'.
At C:\Documents and Settings\Administrator\Desktop\test.ps1:8 char:57
+             $CurrentPort = New-Object PsObject -Property  <<<< @{
New-Object : A parameter cannot be found that matches parameter name 'Property'.
At C:\Documents and Settings\Administrator\Desktop\test.ps1:8 char:57
+             $CurrentPort = New-Object PsObject -Property  <<<< @{
PS C:\Documents and Settings\Administrator\Desktop>

I have nearly zero experience with ps so I dont really know why... the last couple of hours I have tried to explore wmi with ps and the wmi objectbrowser. In the objectbrowser I can perfectly see all the stats I need. see the screenshot. Since I have literally no idea how arrays and properties etc. work in ps I hope someone can help me.

regards

https://i.stack.imgur.com/3ycej.png

  • 2
    What excactly does `doesnt work` mean? Error message? Incorrect result? Unexpected result? – vonPryz Oct 15 '13 at 11:48
  • yeah sorry for not clarifying. I have added the error code in the original post! –  Oct 15 '13 at 12:41
  • Can you give the PowerShell version of your server 2003 box ? – JPBlanc Oct 15 '13 at 13:08
  • Are you sure msiscsi_portalinfoclass exists on the target computer ? – JPBlanc Oct 15 '13 at 13:14
  • yeah im certain msiscsi_portalinfoclass exists. as you can see from the attached screenshot and I can use gwmi -namespace root\wmi -class msiscsi_portalinfoclass. the ps version on the 2003 box is 1.0.0.0 –  Oct 15 '13 at 13:21
  • the problem is I this script will be used on multiple systems down the line and I can`t expect them to all have windows 2003 sp2 so I am forced to use powershell 1.0... Therefore my idea to use python instead! –  Oct 15 '13 at 13:28

1 Answers1

0

It's perhaps a typo but you've got a syntax errors here :

Can you try to replace :

        $CurrentPort = New-Object PsObject -Property @{
            Instance = ($portal.instancename).ToUpper()
            Port     = $p.port
            IP       = ([net.ipaddress]$p.ipaddr.IpV4Address).IPAddressToString
        } 

by

        $CurrentPort = New-Object PsObject -Property @{ `
            Instance = ($portal.instancename).ToUpper();`
            Port     = $p.port;`
            IP       = ([net.ipaddress]$p.ipaddr.IpV4Address).IPAddressToString `
        } 

or

    $CurrentPort = New-Object PsObject -Property @{Instance = ($portal.instancename).ToUpper();Port= $p.port;IP= ([net.ipaddress]$p.ipaddr.IpV4Address).IPAddressToString            } 
JPBlanc
  • 70,406
  • 17
  • 130
  • 175