Forum Discussion
Working powershell script sample for (remote disable nodes/pools)?
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
- Phoenix14467Oct 04, 2022Nimbostratus
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.
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com