I am following this Microsoft document Remove-AzStorageBlob (Az.Storage) | Microsoft Docs I am trying to delete a blob including above command in PowerShell function like below:
$rgName="*******"
$storage="******"
$container="*****"
$blob="my_blob_name"
Connect-AzAccount
Function DeleteBlob
{
$storage=Get-AzStorageAccount -ResourceGroupName $rgname -Name $storage
$ctx=$storage.Ctx
Remove-AzStorageBlob -Container $container -Ctx $ctx -Blob $blob
}
DeleteBlob
After running the above script, I am getting the below error:
Remove-AzStorageBlob : A parameter cannot be found that matches parameter name 'Ctx'.
At line:21 char:52
+ Remove-AzStorageBlob -Container $container -Ctx $ctx -Blob $b ...
+ ~~~~
+ CategoryInfo : InvalidArgument: (:) [Remove-AzStorageBlob], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.WindowsAzure.Commands.Storage.Blob.RemoveStorageAzureBlobCommand
Did anyone face the error like above, please help me solving the error.
Please note that Ctx
doesn't exist in PowerShell.
To resolve the error, try replacing Ctx
with Context
.
I tried the same in my environment by modifying the script like below and got the results successfully:
$resourceGroupName="*******"
$storageAccName="******"
$containerName="*****"
$blobName="my_blob_name"
Connect-AzAccount
Function DeleteBlob
{
$storageAcc=Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccName
$ctx=$storageAcc.Context
Remove-AzStorageBlob -Container $containerName -Context $ctx -Blob $blobName
}
DeleteBlob
Before running the above script, I have blob in my Portal like below:
After running the above script, the blob got deleted successfully like below: