Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- .SYNOPSIS
- Create an addon to upload the current tab's script to pastebin.
- .DESCRIPTION
- This script allows you to create a powershell_ise addon (alt+z) that will upload the current tab to pastebin.com
- .NOTES
- Can't set the paste to private for some reasons.
- api_folder_key could potentially be empty (not tested).
- .EXAMPLE
- Just run the script to create the addon.
- .LINK
- https://pastebin.com/WR4tj8EA
- #>
- $MyAddon = $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus | ?{$_.DisplayName -eq "SendToPastebinAsPS"}
- If($MyAddon -ne $null)
- {
- $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Remove($MyAddon)
- }
- [void]$psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Add("SendToPastebinAsPS",{
- $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
- $headers.Add("Content-Type", "application/x-www-form-urlencoded")
- $api_dev_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
- $api_user_name = "xxxxxxxxx"
- $api_user_password = "xxxxxxxxxxxxx"
- $api_option = "paste"
- $api_paste_code = $psise.CurrentFile.Editor.Text
- $api_paste_private = 2
- $api_paste_name = $psise.CurrentFile.DisplayName
- $api_paste_expire_date = "N"
- $api_paste_format = "powershell"
- $api_folder_key = "xxxxxxxx"
- $api_user_name = [uri]::EscapeDataString($api_user_name)
- $api_user_password = [uri]::EscapeDataString($api_user_password)
- $api_paste_name = [uri]::EscapeDataString($api_paste_name)
- $api_paste_code = [uri]::EscapeDataString($api_paste_code)
- $getuserKey = "api_dev_key=$api_dev_key&api_user_name=$api_user_name&api_user_password=$api_user_password"
- try {
- $userKey = Invoke-RestMethod 'https://pastebin.com/api/api_login.php' -Method 'POST' -Headers $headers -Body $getuserKey
- }
- catch {
- Write-Host "Something went wrong."
- Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__
- Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription
- }
- $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"
- try {
- $upload = Invoke-RestMethod 'https://pastebin.com/api/api_post.php' -Method 'POST' -Headers $headers -Body $uploadPaste
- }
- catch {
- Write-Host "Something went wrong."
- Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__
- Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription
- return
- }
- Write-Host $('[copied to clipboard] Pastebin URL: {0}' -f $upload) -ForegroundColor Green -BackgroundColor Blue
- [System.Windows.Forms.Clipboard]::SetText( $upload, 'UnicodeText' )
- },"Alt+Z")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement