powershell
28 TopicsPowershell: Invoke-RESTmethod on /mgmt/tm/sys/ucs (403) Forbidden error
I'm fairly experienced with Powershell and have used the Invoke-RestMethod cmdlet, and vendor documentation, to automate some things before. I've just inherited management of an HA pair of F5 BIG-IPs. We're not in a position to get BIG-IQ right now, and from looking at notes the previous admin was just logging in and manually creating a UCS archive and downloading it on the weekly. Of course my first thought was that I could automate this. I was able to successfully authenticate against one of the appliances with Invoke-RestMethod and do an HTTP GET to retrieve a list of current UCS files present. However, when I change the method to POST and add in the appropraite Body parameters (in JSON) I get a 403 forbidden error: {"code":403,"message":"Operation is not allowed on component /sys/ucs.","errorStack":[],"apiError":1} the documentation here seems to allude that this should be possible: K13225405 Here's more or less what I'm working with so far: $uri = "/mgmt/tm/sys/ucs" $BigIP = "192.168.1.10" $link = "https://$BigIP$uri" $headers = @{} $headers.Add("ServerHost", $Bigip) $headers.Add("Content-Type", "application/json") $Body = @{ Name = "/var/local/ucs/test_ucs.ucs" Command = "save" } $mycreds = Get-Credential $obj = Invoke-RestMethod -Method POST -Headers $headers -Body ($Body | ConvertTo-Json) -Uri $link -Credential $mycreds3.4KViews0likes19CommentsCreate a IFile {system level} via API - Powershell
Hi All, Attempting the following: 1: Create iFile system level 2: Update existing iRule-> iFile referance the the file uploaded in step 1. Im getting stuck at step 1, any assistance creatly apprecuated. What I have tried: Get Auth Token: # Get API token $big_ip = 'https://[REDACTED]' $url = "{0}{1}" -f $big_ip, '/mgmt/shared/authn/login' $body = @{ username = "[REDACTED]" password = '[REDACTED]' loginProviderName = "tmos" } | ConvertTo-Json $result = Invoke-RestMethod -Method 'POST' -Uri $url -ContentType 'application/json' -Body $body $token = $($result.token.token) Works. Next, Upload my file: $File_Name = 'MyFile' $File_Upload = 'C:\Temp\MyFile' $url = "{0}{1}{2}" -f $big_ip, "/mgmt/shared/file-transfer/uploads/", $File_Name $filelength = (Get-Item $File_Upload).length $headers = @{ 'Content-Type' = 'application/octet-stream' 'X-F5-Auth-Token' = $token 'Content-Range' = "0-$($filelength-1)/$filelength" } $result = Invoke-RestMethod -Method Post -Uri $url -Headers $headers -InFile $File_Upload Works fine too I am returned with: remainingByteCount : 0 usedChunks : @{0=46321} totalByteCount : 46321 localFilePath : /var/config/rest/downloads/MyFile temporaryFilePath : /var/config/rest/downloads/tmp/MyFile generation : 0 lastUpdateMicros : 1661257236246203 Next is where im stuck, creation of the iFile system level from the uploaded file. Ive re-typed the below from the Curl samples here:Syncing local repositories and ifiles using iContr... - DevCentral (f5.com) ### Create a iFile {system level} - does not yet work $File_Name = 'MyFile' $url = "{0}{1}{2}" -f $big_ip, "/mgmt/tm/sys/file/ifile/", $File_Name $headers = @{ 'Content-Type' = 'application/json' 'X-F5-Auth-Token' = $token } $body = @{ 'name' = $File_Name 'source-path' = "file:///var/config/rest/downloads/$File_Name" } | ConvertTo-Json $result = Invoke-RestMethod -Method put -Uri $url -Headers $headers -Body $body Next I am recieving that the file cannot be found. So this query is incorrectly tructured ? Translated these examples to powershell: Syncing local repositories and ifiles using iContr... - DevCentral (f5.com) Invoke-RestMethod : {"code":404,"message":"01020036:3: The requested iFile (/Common/MyFile) was not found.","errorStack":[],"apiError":3} At line:1 char:11 + $result = Invoke-RestMethod -Method put -Uri $url -Headers $headers - ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand Any assistance appreated with the above & next up updating the iRule file refence.Solved1.9KViews1like10CommentsBackup F5 BigIP using RestAPI and PowerShell (again?)
Hello! I went through the Forum and I saw a lot of related messages but none of them actually answered my question. The documentation [I found] leaves to be desired and I hope that the community is able to help me. I am looking for a simple "backup everything and store as a file" solution and it looks like it is much more than just 2-3 RestAPI calls. So, I am able to connect and get a token. Now, I am googling the "Create Backup" command and nothing works. Could you please point me to the exact link that will create a new backup? I also think that it could be a "story" to download the backup, so I will be happy to get any advice on that also. Thanks.Solved1.9KViews0likes6CommentsCall Powershell Script from Unix Shell Script
Hi All, Trust you're all having a great day. I have a powershell script on my Windows server which does some active directory operations. I wish to call that script from another Linux machine using a shell script. I have installed powershell server on my Windows server and can communicate with my linux machine using key based ssh authentication. The issue is that my script just stops once the command for ssh to Windows server is executed. My shell script below: !/bin/bash echo "script run" GROUP=$1 ACCOUNT=$2 ssh Administrator@ sleep 10 echo "\scriptname.ps1 -group $GROUP -account $ACCOUNT" sleep 5 echo "exit" exit I have tried without the echo command as well and it still hangs. Any idea what I must be doing wrong here? How can I make it work please? Regards, GauravSolved1.1KViews0likes3Commentsplink command in powershell | problem with imish
Hi I'm trying to send "imish" command via powershell to f5 and it is not working I tried: imish run /util imish -r 0 both ways did not work I also tried to send the command in the same line like this: plink admin@192.168.1.1 -pw 12345 imish and via external file like this: plink admin@192.168.1.1 -pw 12345 -m E:\myfolder\imishcommand.txt Any other command like "show" or "list" is working fine If I do it gradually, step by step, first by passing the credentials and then when I'm in I write the "imish" command, it is working fine The user I'm using has the administrator level. I also tried with the local "admin" user and the "root" user. Why I'm not able to send the imish command along with the plink command Alternatively, if there is a way to check "show ip ospf neighbor" without entering the "imish"1.1KViews0likes1CommentPowerShell - How to modify system iFile?
I use PowerShell to upload a text file containing a number of parameters that I want to use in an existing iRule. Through the web-gui I have already created an iFile named 'iFileApiKeys'. In PowerShell I use this procedure to upload the text file: $length = "0-" + ($fileContent.Length - 1) + "/" + $fileContent.Length $headers = @{ "Content-Range" = $length} $uploadResult = Invoke-WebRequest $URL -Method POST -Headers $headers -InFile $filePathPlusTextfile - ContentType "multipart/form-data" -TimeoutSec 20 -Credential $mycreds | ConvertFrom-Json Write-Host "Upload Result:" Write-Host $uploadResult According to the 'uploadResult' the file ends up in the folder:'var/config/rest/downloads/iFileApiKeys.txt' on my F5 LTM Using 'SuperPutty' I can via tmos (tmsh) modify the existing system iFile by executing: `tmos> modify /sys file ifile iFileApiKeys source-path file:///var/config/rest/downloads/iFileApiKeys.txt My problem is that I can't seem to find the correct PowerShell command to achieve the same result as the tmos (tmsh) command does. I want to use and actually think I should use: `Invoke-Webrequest -Method Put` I've been trying to emulate an example taken from a Jason Rahm post on this site: https://devcentral.f5.com/articles/getting-started-with-icontrol-working-with-the-system-20592 Like this: $sysIfilePath = "/mgmt/tm/sys/file/ifile/iFileApiKeys" `$sysPath = "https://" + $host_address + $sysIfilePath $updateresult = Invoke-WebRequest -Method Put -Uri $sysPath -Headers $headers -Credential $mycreds -Body $body But this command fails unfortunately, My assumption is that I don't fill $headers and/or $body with the correct values. When executing a GET for my sys iFile object the result is: ``{"kind":"tm:sys:file:ifile:ifilestate","name":"iFileApiKeys","fullPath":"iFileApiKeys","generation":10970077,"selfLink":"https://localhost/mgmt/tm/sys/file/ifile/iFileApiKeys?ver=13.1.0.2","chec ksum":"SHA1:878:52a261b5a113db5c9421a54e1e8b5685e7da7a4d","createTime":"2018-11-26T22:52:08Z","createdBy":"per.eriksson","lastUpdateTime":"2018-12-08T19:49:15Z","mode":33188,"revision":24,"size" :878,"sourcePath":"file:///var/config/rest/downloads/iFileApiKeys.txt","updatedBy":"per.eriksson"} Anyone out there that can point me in the right direction on how to update my sys iFile using PowerShell? Thank you! /Per740Views0likes2CommentsChange Virtual Server Profile
Hi!, I'm trying to change the Http profile on a group of virtual servers using the icontrol snapin for powershell, but when i keep getting errors here is my code $http_profile = New-Object iControl.LocalLBVirtualServerVirtualServerProfile $http_profile.profile_name = $profileName $http_profile.profile_context = "PROFILE_CONTEXT_TYPE_ALL" $http_profile = (,$http_profile) (Get-F5.iControl).LocalLBVirtualServer.add_profile($VirtualServer,$http_profile) When i execute this code i get the following error .. "Exception caught in LocalLB::urn:iControl:LocalLB/VirtualServer::add_profile() Exception: Common::OperationFailed primary_error_code : 17236119 (0x01070097) secondary_error_code : 0 error_string : 01070097:3: Virtual server www.devstage1.test.com_https lists duplicate profiles." Does anyone have any idea? or knows the correct way to perform this task? Thanks, Horacio699Views0likes6CommentsHow to setup F5 LTM to allow powershell commands through VIP to exchange servers for Airwatch
We have recently purchased F5 LTM to loadbalance MS Exchange 2010. Used Iapp to set it up and it works great. Now we are looking to deploy Airwatch for mobile devices and Airwatch needs to use powershell to talk to the exchange servers. I have been searching high and low and don't seem to see what I need to configure for powershell through VIP. We are using same URL structure as email vip, example https://exch01.com/owa (works) https://excho1.com/powershell (doesn't work). Any tips,trick, or config help would be greatly appreciated. Thanks!!611Views0likes3CommentsGet Profile_Type_Client_SSL from Virtual Server
I am trying to retrieve the client SSL profile from a list of virtual servers, but I am having difficulties. Any help would be greatly appreciated Here is what I have so far: Get list of virtual servers $vs_list = (Get-F5.iControl).LocalLBVirtualServer.get_list() Get profiles associated with each virtual server $vs_profile_list = (Get-F5.iControl).LocalLBVirtualServer.get_profile($vs_list) I tried this, but get 0 results (GetF5.iControl).LocalLBVirtualServer.get_profile($vs_list).PROFILE_TYPE_CLIENT_SSL599Views0likes6CommentsiControl PS Snapin throws error when calling LocalLBPool.get_member_metadata
iControlSnapin v23 PowerShell v4.0 Hi, I am able to successfully call other LocalLBPool methods. When I attempt to call LocalLBPool.get_member_metadata I receive an error. (Get-F5.iControl).LocalLBPool.get_member_metadata(@('mypool'),@($object)) Exception calling "get_member_metadata" with "2" argument(s): "There is an error in XML document (11, 2)." At line:1 char:64 + (Get-F5.iControl).LocalLBPool.get_member_metadata(@('mypool'),@($object)) + ~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : InvalidOperationException ` Of course I run Initialize-F5.iControl first. I build my $object using this code: `$object = New-Object -TypeName iControl.CommonAddressPort $object.address = 'mynodeaddress' $object.port = 443 ` Here is an example of a method that works fine with that same object: `(Get-F5.iControl).LocalLBPool.get_member_object_status(@('mypool'),@($object)) availability_status enabled_status status_description ------------------- -------------- ------------------ AVAILABILITY_STATUS_GREEN ENABLED_STATUS_ENABLED The DNS server(s) are ... Any ideas? Is the source code for the iControlSnapin available somewhere? Thanks, pimy539Views0likes5Comments