/
accountbackupdelete.ps1
61 lines (46 loc) · 2.09 KB
/
accountbackupdelete.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Copyright 2023 SearchStax, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# -----------------------------------------------------------------------
# account > backup > delete
# PowerShell script for deleting a backup from an account.
# Removes TLS obstacles from connection. Otherwise connections fail.
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12
$USER = "user@company.com"
$PASSWORD = $( Read-Host "Input password, please" -AsSecureString)
$PASSWORD = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($PASSWORD))
$ACCOUNT = "AccountName"
$BUID = "27004"
Write-Host "Asking for an authorization token for $USER..."
Write-Host
$body = @{
username=$USER
password=$PASSWORD
}
Remove-Variable PASSWORD
$body = $body | ConvertTo-Json
$TOKEN = Invoke-RestMethod -uri "https://app.searchstax.com/api/rest/v2/obtain-auth-token/" -Method Post -Body $body -ContentType 'application/json'
Remove-Variable body
$TOKEN = $TOKEN.token
Write-Host "Obtained TOKEN" $TOKEN
Write-Host
# Set up HTTP header for authorization token
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Token $TOKEN")
$RESULTS = Invoke-RestMethod -Method Delete -ContentType 'application/json' -Headers $headers `
-uri "https://app.searchstax.com/api/rest/v2/account/$ACCOUNT/backup/$BUID/"
$RESULTS = $RESULTS | ConvertTo-Json
Write-Host $RESULTS
Write Host "Exit..."
Exit