Forum Discussion

Mike_Schnorr_64's avatar
Mike_Schnorr_64
Icon for Nimbostratus rankNimbostratus
Oct 17, 2007

Powershell Twoi-Dimensional Array

I have been using the iControl assembly from PowerShell. Nice work Joe, I look forward to seeing what you come up with for CMDLets.

I am running into a problem with creating multi-dimensional arrays in PowerShell to pass to functions in the iControl assembly. Example, calling LocalLbVirtualServer.Create:

$testActiveF5.LocalLBVirtualServer.create(@($Definition), @($WildMask), @($Resources), $Profile)

What do I need to do to turn the one profile object into a 2-dimensional array?

Thanks

--Mike

3 Replies

  • Try adding comma before the variable and surround it by parenthesis.

     

     

    $testActiveF5.LocalLBVirtualServer.create(@($Definition), @($WildMask), @($Resources), (,$Profile))

     

     

    Fingers crossed...

     

     

    BTW, the PowerShell SnapIn is on the Labs download page, althought I've made significant enhancements since that was posted so you might want to wait a bit to get my latest code. I'll try to get that uploaded later this week.

     

     

    -Joe
  • No luck. Here is the whole chunk of code I am using as well as the error message in case it helps anyone.

     

     

    
    $Definition
    $Definition = New-Object -TypeName icontrol.CommonVirtualServerDefinition
    $Definition.address = "192.168.1.1"
    $Definition.name = "IControlTest"
    $Definition.port = 80
    $Definition.protocol = "PROTOCOL_TCP"
    $WildMask = "255.255.255.255"
    $Resources = New-Object -typeName iControl.LocalLBVirtualServerVirtualServerResource
    $Resources.default_pool_name = "TestPool"
    $Resources.type = "RESOURCE_TYPE_POOL"
    $Profile = New-Object -typename iControl.LocalLBVirtualServerVirtualServerProfile
    $Profile.profile_name = "http"
    $Profile.profile_context = "PROFILE_CONTEXT_TYPE_ALL"
    $testActiveF5.LocalLBVirtualServer.create(@($Definition), @($WildMask), @($Resources), (,$Profile))

     

     

    > $testActiveF5.LocalLBVirtualServer.create(@($Definition), @($WildMask), @($Resources), (,$Profile))

     

    Cannot convert argument "3", with value: "System.Object[]", for "create" to type "iControl.LocalLBVirtualServerVirtualS

     

    erverProfile[][]": "Cannot convert "iControl.LocalLBVirtualServerVirtualServerProfile" to "iControl.LocalLBVirtualServe

     

    rVirtualServerProfile[]"."

     

    At line:1 char:42

     

    + $testActiveF5.LocalLBVirtualServer.create( <<<< @($Definition), @($WildMask), @($Resources), (,$Profile))
  • Looks like this works. There is probably a prettier (more PowerShelly) way to do this, but I am going this route for now.

    
    $profileArray = new-object "iControl.LocalLBVirtualServerVirtualServerProfile[][]" 1,1
    $profileArray[0][0] = $Profile