cgaines22_14499
Mar 22, 2016Nimbostratus
PowerShell Help with JSON and Invoke-WebRequest
This is the F5
$MyLTM_IP = '10.5.183.4'
Load the SnapIn first
Add-PSSnapIn iControlSnapIn
Need to create Login
$secpasswd = ConvertTo-SecureString 'password1' -AsPlainText -Force$mycreds = New-Object System.Management.Automation.PSCredential ('user1', $secpasswd)
Initialize-F5.iControl first by logging into F5
Initialize-F5.iControl -HostName "$MyLTM_IP" -PSCredentials $mycreds
This shows the available partitions
(Get-F5.iControl).ManagementPartition.get_partition_list()
This command shows all of the actions available to the F5.
Invoke-WebRequest -Method GET -URI '[https://10.5.183.4/mgmt/tm/ltm](https://10.5.183.4/mgmt/tm/ltm)'-Credential $mycreds
A modification of an existing object requires the PUT method, POST is for object creation.
Fails:
Invoke-WebRequest -Method POST -Uri '[https://10.5.183.4/mgmt/tm/ltm/pool](https://10.5.183.4/mgmt/tm/ltm/pool)' { "name":"cpg-pool2", "partition":"CL-COM_SELFSERV", "members" : [{"name":"10.5.183.199", "description":"Web server"}] }
Fails:
Invoke-WebRequest -Method POST -Uri '[https://10.5.183.4/mgmt/tm/ltm/pool/~CL-COM_SELFSERV~cpg-pool2](https://10.5.183.4/mgmt/tm/ltm/pool/~CL-COM_SELFSERV~cpg-pool2) [{"name":"10.5.183.199", "description":"Web server"}]'
Fails:
Invoke-WebRequest -Method POST -Uri '[https://10.5.183.4/mgmt/tm/ltm/node/~CL-COM_SELFSERV](https://10.5.183.4/mgmt/tm/ltm/node/~CL-COM_SELFSERV)' [{"name" : "10.5.183.199", "description" : "Web server"}]'
PS U:> Invoke-WebRequest -Method POST -Uri '[https://10.5.183.4/mgmt/tm/ltm/pool/~CL-COM_SELFSERV~cpg-pool2](https://10.5.183.4/mgmt/tm/ltm/pool/~CL-COM_SELFSERV~cpg-pool2) [{"name":"10.5.183.199", "description":"Web server"}]'
Invoke-WebRequest : The remote server returned an error: (401) Unauthorized.At line:1 char:1
+ Invoke-WebRequest -Method POST -Uri '[https://10.5.183.4/mgmt/tm/ltm/pool/~CL-COM](https://10.5.183.4/mgmt/tm/ltm/pool/~CL-COM) ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
I am trying to add a new Node 10.5.183.199 to the existing Pool cpg-pool2 that is located in the Partition CL-COM_SELFSERV. I have tried different variations and the Invoke-WebRequest works for other commands.
What am I missing other than not understanding where the ~ is used and when [ ] JSON is used?