Forum Discussion
Mike_Schnorr_64
Nimbostratus
Oct 17, 2007Powershell 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 - Mike_Schnorr_64
Nimbostratus
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)) - Mike_Schnorr_64
Nimbostratus
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
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects
