Forum Discussion

tharrison_91509's avatar
tharrison_91509
Icon for Nimbostratus rankNimbostratus
Jul 17, 2012

PowerShell: Create Virtual Server

I have been tasked with writing a script using PowerShell to 'rename' several Virtual Servers in our BIG-IP. I have downloaded the iControl tool & the PowerShell cmdlets and they are connecting to our F5 just fine. I can't find any functionality to make a copy of an existing virtual server with a new name, so I was intending to go, one-by-one through our Virtual Servers, gather all information from them and then create new ones using that information with the new name. The current snag I'm running into is creating a Virtual Server with no HTTP profile. When I run this code, I get an error:

 

 

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.