William
William

Reputation: 82

New-AzStorageShare Powerhsell Cmdlet Fails because "Server failed to authenticate the request."

I am trying to re-write a powershell functions that creates a new Storage Share and File share with specific settings. All of the customization works, however it fails on the last line. I tried using Storage Account Keys to create the storage share amongst other things. Here is the relevant code:

$storageAccountName = "filestest2"
$storageContext = New-AzStorageContext -StorageAccountName $storageAccountName
New-AzStorageShare -Name "pubs" -Context $storageContext

The Storage account already exists because it is created earlier in the function. Here is the line that I use to create the Storage Account. All the variables are defined.

$storageAccount = New-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName -SkuName Premium_LRS -location $location -Kind "FileStorage" `
          -enableLargeFileShare -AllowBlobPublicAccess $false  -EnableAzureActiveDirectoryDomainServicesForFile $true

This is the actual error message. I can't find anything relating to my issue and this error message online.

New-AzStorageShare : Server failed to authenticate the request. Make sure the value of Authorization header is formed
correctly including the signature. HTTP Status Code: 403 - HTTP Error Message: Server failed to authenticate the
request. Make sure the value of Authorization header is formed correctly including the signature.
ErrorCode: AuthenticationFailed
ErrorMessage: Server failed to authenticate the request. Make sure the value of Authorization header is formed
correctly including the signature.
RequestId:5ba2ea9d-201a-0028-0837-747c83000000
Time:2021-07-08T20:23:15.5271563Z
AuthenticationErrorDetail: Authentication scheme Bearer is not supported for Files.
At line:1 char:1
+ New-AzStorageShare -Name "pubs" -Context $storageContext
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [New-AzStorageShare], StorageException
    + FullyQualifiedErrorId : StorageException,Microsoft.WindowsAzure.Commands.Storage.File.Cmdlet.NewAzureStorageShare

This seems to be a fairly recent, and new issue. This exact function used to work a month ago (that's when I originally wrote it).

I found a similar thread here, however I tried following what it said and it did not work. (My time is not off, and I tried using the keys like I said above)

.

EDIT: According to one of the comments, I tried using Set-AzCurrentStorageAccount. I reduced my code to 4 lines so that nothing else could be causing a problem (all of my configuration).

$storageAccount = New-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName -SkuName Premium_LRS -location $location
    
    Set-AzCurrentStorageAccount -ResourceGroupName $resourceGroupName -StorageAccountName $storageAccountName
    
    $fileshareName = "pubs"

    New-AzStorageShare -name $fileShareName 

This error Message is:

New-AzStorageShare : An error occurred while sending the request.
At C:\scripts\functions.ps1:2201 char:5
+     New-AzStorageShare -name $fileShareName
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [New-AzStorageShare], StorageException
    + FullyQualifiedErrorId : StorageException,Microsoft.WindowsAzure.Commands.Storage.File.Cmdlet.NewAzureStorageShar
   e

Upvotes: 0

Views: 942

Answers (1)

Bhargavi Annadevara
Bhargavi Annadevara

Reputation: 5502

I had run into the same issue earlier and found this related thread.

The workaround specified by @blueww resolved the issue for me, which is to set the current storage account with Set-AzCurrentStorageAccount cmdlet before creating the new file share:

Set-AzCurrentStorageAccount -ResourceGroupName "Resource-Group-Name" -StorageAccountName "Storage-Account-Name"
New-AzStorageShare -Name "MyStorageShare" -Context $storageContext

Check if this helps.

..

EDIT: This is the working script I'm running:

#New-AzStorageShare.ps1

$resourceGroupName = "Resource-Group-Name"
$storageAccountName = "Storage-Account-Name"
$region = "westus2"

$storageAccount = New-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName -SkuName Premium_LRS -location $region -Kind "FileStorage"

Set-AzCurrentStorageAccount -ResourceGroupName $resourceGroupName -StorageAccountName $storageAccountName

New-AzStorageShare -Name "pubs"

Upvotes: 1

Related Questions