Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This PowerShell script is part of video https://www.youtube.com/watch?v=BI7F4-4zfEY
- #---------------------------------------------------------------------
- # Date : 28-09-2017
- # Script name : Remove message using_PowerShell.ps1
- # Description : This script will remove messages from a
- # Service Bus queue.
- #
- # Created by : Basic Cloud
- # Extra module :
- # Copyright : ©2017 Basic Cloud, all rights reserved.
- # History : Basic Cloud 20170928 Initial version
- #---------------------------------------------------------------------
- <#
- # only run this code if you do not have a SAStoken.
- [Reflection.Assembly]::LoadWithPartialName("System.Web")| out-null
- # Enter the information about the Service Bus
- $URI="basiccloud.servicebus.windows.net/basiccloud/messages/head"
- $Access_Policy_Name="basiccloud"
- $Access_Policy_Key="fVGxhG2j5tJIGHstH6hoX7rVKLoOAMHaycnWJnCE/r8="
- # Set the token expiration
- $Expires=([DateTimeOffset]::Now.ToUnixTimeSeconds())+300
- # Build the token
- $SignatureString=[System.Web.HttpUtility]::UrlEncode($URI)+ "`n" + [string]$Expires
- $HMAC = New-Object System.Security.Cryptography.HMACSHA256
- $HMAC.key = [Text.Encoding]::ASCII.GetBytes($Access_Policy_Key)
- $Signature = $HMAC.ComputeHash([Text.Encoding]::ASCII.GetBytes($SignatureString))
- $Signature = [Convert]::ToBase64String($Signature)
- $SASToken = "SharedAccessSignature sr=" + [System.Web.HttpUtility]::UrlEncode($URI) + "&sig=" + [System.Web.HttpUtility]::UrlEncode($Signature) + "&se=" + $Expires + "&skn=" + $Access_Policy_Name
- # Output the value
- $SASToken
- #>
- # Remove messages from the Service Bus queue
- $header = @{"Authorization"="$SASToken"}
- 0..5000 | ForEach-Object `
- -Begin { "Removing"; $counter = 0 } `
- -Process {
- Invoke-RestMethod -Uri https://basiccloud.servicebus.windows.net/basiccloud/messages/head -Method Delete -Headers $header
- } `
- -End { "Finished: $counter" }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement