21-Jul-2017 11:47
Hello everyone, I am trying to find a working powershell script sample on how to remotely disable nodes and pools. If anyone can point me at the right direction that will be awesome!
Build: BIG-IP 12.1.1 Build 2.0.204 Hotfix HF2
Thanks, Daniel
22-Jul-2017
16:01
- last edited on
03-Jun-2023
09:56
by
JimmyPackets
Joel Newton has written a powershell module:
https://devcentral.f5.com/codeshare/powershell-module-for-the-f5-ltm-rest-api
Or, if you want to do it with Pure rest I've got a guide here on how to authenticate against the F5 using Powershell:
https://loadbalancing.se/2017/05/10/using-f5-rest-api-with-roles/
Working script to disable a member and node:
$User = "admin"
$Password = "admin"
$f5 = "yourf5.domain.local"
Create the string that is converted to Base64
$pair = $user + ":" + $Password
Encode the string to base64
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
Add the "Basic prefix"
$basicAuthValue = "Basic $encodedCreds"
Prepare the headers
$headers = @{
"Authorization" = $basicAuthValue
"Content-Type" = "application/json"
}
Create the body of the post
$body = @{"username" = $User; "password" = $Password; "loginProviderName" = "tmos" }
Convert the body to Json
$body = $Body | ConvertTo-Json
$response = Invoke-WebRequest -Method "POST" -Headers $headers -Body $body -Uri "https://$f5/mgmt/shared/authn/login"
Extract the token from the response
$token = ($response.content | ConvertFrom-Json).Token.token
Prepare a dictionary with the token
$headers = @{
"X-F5-Auth-Token" = $token;
"content-type" = "application/json";
}
Create the body of the post
$body = @{"state" = "user-down"; "session" = "user-disabled"; }
Convert the body to Json
$body = $Body | ConvertTo-Json
Disable member
$response = Invoke-WebRequest -Method "PUT" -Headers $headers -Body $body -Uri "https://$f5/mgmt/tm/ltm/pool/jira.domain.local-8080_pool/members/~Common~server.domain.local:8080/"
Disable node
$response = Invoke-WebRequest -Method "PUT" -Headers $headers -Body $body -Uri "https://$f5/mgmt/tm/ltm/node/~Common~server.domain.local/"
/Patrik
04-Oct-2022 05:46
It should be noted that if the PUT request isn't properly crafted that that command can blank out metadata in your nodes in the F5. For example, if you only have state and session in your PUT request, your friendly name will be changed to the IP address and the display name will be cleared.