How to ignore Get-AzStorageBlobContent NullReferenceException error as file still downloads

314 Views Asked by At

I have a PSScript works, but the command Get-AzStorageBlobContent always throws the same error when file still downloads, even the script is compete and I verified the files are downloaded to the specified local folder sucessfully, how to ignore these errors? I tried to catch the error and just ignored it, but looks like it won't come to catch section. enter image description here For each blob image, it has one error throwing, as you can see it doesn't step into the catch statement (the screeshot 1). How to ignore below error? or just get warning? enter image description here

1

There are 1 best solutions below

1
Venkatesan On

You can use the command (ErrorAction SilentlyContinue) to avoid errors and continue the execution of the command in the console.

Command:

$repo= "your-local-path"
$blobUri="<your-blob-uri>"

Get-AzStorageBlobContent -Uri $blobUri -Destination $repo -ErrorAction SilentlyContinue

Output:

   AccountName: <Your-account-name>, ContainerName: <container-name>

Name                 BlobType  Length          ContentType                    LastModified         AccessTier SnapshotTime              
----                 --------  ------          -----------                    ------------         ---------- ------------              
sample.mp4           BlockBlob 1055736         application/octet-stream       2023-05-09 05:41:28Z Hot 
 

enter image description here

Otherwise, try assigning Get-AzStorageBlobContent command as a variable like the below:

$repo= "your-local-path"
$blobUri="<your-blob-uri>"
try{
$blobcontent=Get-AzStorageBlobContent -Uri $blobUri -Destination $repo
Write-Host $blobcontent.name
Write-Host $blobcontent.length
}
catch{
Write-Host "nullreference exception"
}

Output:

sample.mp4
1055736

enter image description here

Reference: Everything you wanted to know about exceptions - PowerShell | Microsoft Learn