How to remove a Stored Access Policy of a Container in Microsoft Azure (PowerShell)
Introduction
This script sample shows how to remove a stored access policy of a container in Microsoft Azure.
Scenarios
A stored access policy gives users greater control over shared access signatures we have released. If they want to revoke access within a specified time of period, a simply way is to remove the underlying container-level policy. This script can remove the stored access policy easily.
Script
Step 1: From the Start Screen or the Start Menu, search for Windows Azure PowerShell. Right-click the Windows Azure PowerShell entry and select Run as Administrator.
Note: If Windows Azure PowerShell is not installed, see Getting Started with Windows Azure PowerShell Cmdlets for installation and configuration information.
Step 2: If you want to get a list of all cmdlet help topics, type the command Get-Help C:\Script\ RemoveStoredAccessPolicy.ps1 -Full to display the entire help file for this function, such as the syntax, parameters, or examples. This is shown in the following figure.
Example
Example 1: Type C:\Script\ RemoveStoredAccessPolicy.ps1 -StorageAccountName "storageaccount" -ListAccessPolicy command in the Windows PowerShell Console.
This example shows how to list all stored access policies of a container.
Example 2: Type C:\Script\ RemoveStoredAccessPolicy.ps1 -StorageAccountName "storageaccount" -StoredAccessPolicy "Policy1" command in the Windows PowerShell Console.
This example shows how to remove a Stored Access Policy named Policy1.
Here are some code snippets for your reference.
#Remove the specified stored access policy
If($StoredAccessPolicy)
{
Foreach($Policy in $StoredAccessPolicy)
{
Write-Verbose "Removing Stored Access Policy."
$Result = $Permission.SharedAccessPolicies.Remove($Policy)
$BlobContainer.SetPermissions($Permission)
If($Result)
{
Write-Host "Successfully removed Stored Access Policy '$Policy'."
}
Else
{
Write-Host "Failed to remove stored access policy '$Policy', please check this policy is existing."
}
}
}
#Remove the specified stored access policy If($StoredAccessPolicy) { Foreach($Policy in $StoredAccessPolicy) { Write-Verbose "Removing Stored Access Policy." $Result = $Permission.SharedAccessPolicies.Remove($Policy) $BlobContainer.SetPermissions($Permission) If($Result) { Write-Host "Successfully removed Stored Access Policy '$Policy'." } Else { Write-Host "Failed to remove stored access policy '$Policy', please check this policy is existing." } } }
Windows PowerShell 3.0
Windows Azure PowerShell
Microsoft All-In-One Script Framework is an automation script sample library for IT Professionals. The key value that All-In-One Script Framework is trying to deliver is Scenario-Focused Script Samples driven by IT Pros' real-world pains and needs. The team is monitoring all TechNet forums, IT Pros' support calls to Microsoft, and script requests submitted to TechNet Script Repository. We collect frequently asked IT scenarios, and create script samples to automate the tasks and save some time for IT Pros. The team of All-In-One Script Framework sincerely hope that these customer-driven automation script samples can help our IT community in this script-centric move.