Skip to content

Instantly share code, notes, and snippets.

@jaredhaight
Last active June 18, 2018 22:11
Show Gist options
  • Save jaredhaight/b796044542ada6c58d9d9be275b68bd1 to your computer and use it in GitHub Desktop.
Save jaredhaight/b796044542ada6c58d9d9be275b68bd1 to your computer and use it in GitHub Desktop.
$token = '' # Get from: https://api.slack.com/custom-integrations/legacy-tokens
$user = Invoke-RestMethod -Uri "https://slack.com/api/auth.test?token=$token"
# Making sure we're on the right account. Thanks @veegr!
$user | Select-Object Url, Team, User | format-list
Write-Output "Is this the correct account?"
$choice = Read-Host "[Y/N]"
Switch ($choice) {
Y {Write-Output "`nDeleting with great vengeance and furious anger`n"}
N {
Write-Output "Exiting."
exit
}
default {
Write-Warning "Somehow you managed to enter something besides Y or N"
exit
}
}
$userId = $user.user_id
$time = 1508396400 # https://www.wolframalpha.com/input/?i=15+days+ago+in+epoch
$files = Invoke-RestMethod -Uri "https://slack.com/api/files.list?token=$token&user=$userId&count=999&ts_to=$time"
forEach ($file in $files.files) {
$fileId = $file.id
Write-Output "[*] Deleting $fileId"
$result = Invoke-RestMethod -Uri "https://slack.com/api/files.delete?token=$token&file=$fileId"
if ($result.ok) {
Write-Output "[*] Deleted $fileId"
}
else {
Write-Output "[!] Error: $($result.error)"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment