Forum Discussion
PowerShell: Create Virtual Server
Add-PSSnapIn iControlSnapIn
$creds = get-credential
$username = ($creds.username).replace("\","")
$password = $creds.GetNetworkCredential().password
Initialize-F5.iControl -Hostname 1.1.1.1 -Username $username -Password $password
$IC = Get-F5.iControl
CODE TO CREATE VIP
$VirtualDefinition = $null
$WildMask = $null
$Resources = $null
$Profile = $null
$Profile_Array = $null
$VirtualDefinition = New-Object icontrol.CommonVirtualServerDefinition
$VirtualDefinition.address = "10.10.10.50"
$VirtualDefinition.name = "TestVirtual"
$VirtualDefinition.port = 80
$VirtualDefinition.protocol = "PROTOCOL_TCP"
$WildMask = "255.255.255.255"
$Resources = New-Object iControl.LocalLBVirtualServerVirtualServerResource
$Resources.default_pool_name = ""
$Resources.type = "RESOURCE_TYPE_POOL"
$Profile = New-Object iControl.LocalLBVirtualServerVirtualServerProfile
$Profile.profile_name = "Blank"
$Profile.profile_context = "PROFILE_CONTEXT_TYPE_ALL"
$Profile_Array = new-object "iControl.LocalLBVirtualServerVirtualServerProfile[][]" 1,1
$Profile_Array[0][0] = $Profile
$ic.LocalLBVirtualServer.create($VirtualDefinition, $WildMask, $Resources, $Profile)
... here is the error:
Exception calling "create" with "4" argument(s): "Exception caught in LocalLB::urn:iControl:LocalLB/VirtualServer::create()
Exception: Common::OperationFailed
primary_error_code : 16908342 (0x01020036)
secondary_error_code : 0
error_string : 01020036:3: The requested profile () was not found."
At U:\Powershell\(TESTING)F5-Scripting.ps1:33 char:32
+ $ic.LocalLBVirtualServer.create <<<< ($VirtualDefinition, $WildMask, $Resources, $Profile)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
... I'd like to be able to create one with no HTTP Profile at all, if possible. Thanks in advance for any assistance. I can't find a lot of good documentation on how to use PowerShell to manipulate iControl and even less on creating Virtual Servers.
- Hi,
- tharrison_91509NimbostratusJoe - thanks for those links... very helpful indeed, but it sounds like you're saying there's no way to create a "blank" Virtual Server without any profiles selected at all as you can in the GUI? Forgive me if I sound a bit ignorant - I'm a scripting systems guy tasked with writing some stuff for the networking team to use. In the GUI, I am able to create a Virtual Server by specifying only the name, address and service port - everything else is left at "None". This is what I'd like to accomplish using PS and iControl, if possible. Thanks.
- tharrison_91509NimbostratusBump - need some help with this. There has to be a way to create a Virtual Server using PowerShell with no HTTP profile. Just as an example, in the GUI, I can create a Virtual Server with the following settings:
- In looking at the code, you must pass in all parameters of the same 1st dimension size. The server code iterates thru that 1st dimension and then for the profiles, it iterates the 2nd dimension for each of the profiles for the given virtual server in the 1st dimension.
define definitions, wildmasks, and resources parameters declare empty 2-d array $Profile_Array = new-object "iControl.LocalLBVirtualServerVirtualServerProfile[][]", 1,0 Create the virtual VirtualServer.create($definitions, $wildmasks, $resources, $Profile_Array
- tharrison_91509NimbostratusJoe - that worked, but it threw an error:
- Sorry, meant to be more specific in that you shouldn't assign the value to the array as we've allocated it to size zero. Just comment out the $Profile_Array[0][0] = $Profile line. Array element [0][0] is no longer allocated so you can't assign to it.
- tharrison_91509NimbostratusLet me ask you this - is it possible to simply "copy" a Virtual Server? Is there simple code to in effect do just that?
My ultimate goal is to take a list of Virtual Servers that I currently have and in effect rename them. I know I can't rename Virtual Servers (or can I?) so I planned to loop through each Virtual Server, store all of its characteristics in variables and then create a new Virtual Server with a new name and apply each characteristic from the old one to it. It would be far easier if I could simply "copy" a Virtual Server, though....
- Unfortunately there isn't a "copy" option (in the API, GUI, or CLI). the only option for copying would be to edit the config directly and do a manual reload. That would be a nice enhancement request to put in if you really need it though.
- tharrison_91509Nimbostratusso now that I have a grasp on how to create pools and virtual servers, how would I go about retrieving ALL characteristics of a given virtual server or pool? Is there a list somewhere of all the information that PowerShell/iControl can pull from a VIP or pool?
- Brian_RodriguezNimbostratus
I am extremely interested in this as well. My company has two datacenters in two different areas and we use them in a prod/dr configuration. If we create virtual servers in one location, we create an exact replica in our other location, which remains in standby and becomes active if the pool in the primary location goes down. A copy feature would be extremely helpful for these tasks. I would like to create the virtual server in the primary location, then copy it over to the DR location and only have to worry about the new ip addresses. Does anyone know how to script something like this or give me a step-by-step on performing this on the cli?
Thanks In Advance, Brian
Recent Discussions
Related Content
* 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