Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### MoonShot API Boot
- $username = "APIUSERNAME"
- $password = "APIPASSWORD"
- $Moonshot = "MOONSHOTFQDN"
- $Cartridge = "CartridgeName"
- $powerstate = "On/Press/PressAndHold"
- ### Trust Certificate
- add-type @"
- using System.Net;
- using System.Security.Cryptography.X509Certificates;
- public class TrustAllCertsPolicy : ICertificatePolicy {
- public bool CheckValidationResult(
- ServicePoint srvPoint, X509Certificate certificate,
- WebRequest request, int certificateProblem) {
- return true;
- }
- }
- "@
- [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
- # Create the json for the webrequest
- $json_password = @{'UserName' = $username;'Password' = $password}
- $json_password = convertto-json $json_password
- # Authenticate to the API and convert the JSON-response to a Powershell object to collect the token
- $json_token = Invoke-WebRequest -URI "https://$moonshot/rest/v1/Sessions" -Method POST -Body $json_password -ContentType 'application/json'
- $apiKey = $json_token.headers.'X-Auth-Token'
- # Change PowerState
- $powerstate_json = @{'Power' = $powerstate}
- $powerstate_json = convertto-json $powerstate_json
- $result = Invoke-WebRequest -URI "https://$moonshot/rest/v1/Chassis/1/Cartridges/$Cartridge" -Method Patch -Body $powerstate_json -ContentType 'application/json' -Headers @{"X-Auth-Token" = $apiKey}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement