Advertisement
Combreal

SendToPastebin_addon.ps1

Jun 9th, 2021
1,436
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#
  2. .SYNOPSIS
  3. Create an addon to upload the current tab's script to pastebin.
  4.  
  5. .DESCRIPTION
  6. This script allows you to create a powershell_ise addon (alt+z) that will upload the current tab to pastebin.com
  7.  
  8. .NOTES
  9. Can't set the paste to private for some reasons.
  10. api_folder_key could potentially be empty (not tested).
  11.  
  12. .EXAMPLE
  13. Just run the script to create the addon.
  14.  
  15. .LINK
  16. https://pastebin.com/WR4tj8EA
  17. #>
  18.  
  19. $MyAddon = $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus | ?{$_.DisplayName -eq "SendToPastebinAsPS"}
  20. If($MyAddon -ne $null)
  21. {
  22.     $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Remove($MyAddon)
  23. }
  24.  
  25. [void]$psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Add("SendToPastebinAsPS",{
  26.  
  27.     $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
  28.     $headers.Add("Content-Type", "application/x-www-form-urlencoded")
  29.    
  30.     $api_dev_key            = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  31.     $api_user_name          = "xxxxxxxxx"
  32.     $api_user_password      = "xxxxxxxxxxxxx"
  33.     $api_option             = "paste"
  34.     $api_paste_code         = $psise.CurrentFile.Editor.Text
  35.     $api_paste_private      = 2
  36.     $api_paste_name         = $psise.CurrentFile.DisplayName
  37.     $api_paste_expire_date  = "N"
  38.     $api_paste_format       = "powershell"
  39.     $api_folder_key         = "xxxxxxxx"
  40.    
  41.     $api_user_name = [uri]::EscapeDataString($api_user_name)
  42.     $api_user_password = [uri]::EscapeDataString($api_user_password)
  43.     $api_paste_name = [uri]::EscapeDataString($api_paste_name)
  44.     $api_paste_code = [uri]::EscapeDataString($api_paste_code)
  45.    
  46.     $getuserKey = "api_dev_key=$api_dev_key&api_user_name=$api_user_name&api_user_password=$api_user_password"
  47.    
  48.     try {
  49.         $userKey = Invoke-RestMethod 'https://pastebin.com/api/api_login.php' -Method 'POST' -Headers $headers -Body $getuserKey
  50.     }
  51.     catch {
  52.         Write-Host "Something went wrong."
  53.         Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__
  54.         Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription
  55.     }
  56.    
  57.     $uploadPaste = "api_dev_key=$api_dev_key&api_option=$api_option&api_user_key=$userKey&api_folder_key=$api_folder_key&api_paste_expire_date=$api_paste_expire_date&api_paste_code=$api_paste_code&api_paste_name=$api_paste_name&api_paste_format=$api_paste_format"
  58.    
  59.     try {
  60.         $upload = Invoke-RestMethod 'https://pastebin.com/api/api_post.php' -Method 'POST' -Headers $headers -Body $uploadPaste
  61.     }
  62.     catch {
  63.         Write-Host "Something went wrong."
  64.         Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__
  65.         Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription
  66.         return
  67.     }
  68.    
  69.     Write-Host $('[copied to clipboard] Pastebin URL: {0}' -f $upload) -ForegroundColor Green -BackgroundColor Blue
  70.     [System.Windows.Forms.Clipboard]::SetText( $upload, 'UnicodeText' )
  71. },"Alt+Z")
  72.  
  73.  
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement