Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology

iControl Rest Add Vlans to VCMP guest

Hello All,

I have been working automating some of our L2 and L3 tasks and running into a an issue where I am unable to add the created vlans to VCMP Guest. I am using powershell to do that. My understanding is that because the vlans properties in the VCMP guest is not a sub-collection in the guest object then we'll have to query the vlans into a variable, add the new vlans to that variable and add that back to the guest

#Get vlans current vlans from Guest 
$GuestVlans = Invoke-RestMethod "https://BigIPMgmtIP/mgmt/tm/vcmp/guest/GuestName" -Credential $creds -Method GET -ContentType application/json | select -ExpandProperty vlans``

#Add new vlans to $GuestVlans
$GuestVlans += "Common/Newvlan1"
$GuestVlans += "Common/Newvlan2"

Invoke-RestMethod "https://BigIPMgmtIP/mgmt/tm/vcmp/guest/GuestName" -Credential $creds -Method PATCH -ContentType application/json -Body $GuestVlans

#Add the vlans back seems not be working and I am getting the following error

Invoke-RestMethod : {"code":400,"message":"Found invalid JSON body in the request.","errorStack":[]}

I am new to this and trying to learn as much as I can so any of your help will be very welcomed.

Thank you

Rate this Question

Answers to this Question


It looks like you are attempting to patch the contents of the vlans property, when the rest method expects a vcmp guest object. I think you need to stick $GuestVlans back into a guest-like object like (pseudocode) {"vlans":$GuestVlans}, and that may do the trick.

I'm also not certain about the way you are adding vlans, which looks like it will just result in one long string "Common/OriginalVlanCommon/NewVlan1Common/NewVlan2", but I'm not familiar enough with these powershell commands to be certain.

Comments on this Answer
Comment made 07-Apr-2017 by The Y 210

Good call. I 'll definitely give it a try. Thanks for the answer