I have below script which I am trying but getting error
$secret = '*****'
$clientID = '********'
$DirectoryID = '*********'
function getBearer([string]$TenantID, [string]$ClientID, [string]$ClientSecret)
{
$TokenEndpoint = {https://login.windows.net/{0}/oauth2/token?api-version=2018-03-28} -f $TenantID
$ARMResource = "https://storage.azure.com/"
$Body = @{
'resource'= $ARMResource
'client_id' = $ClientID
'grant_type' = 'client_credentials'
'client_secret' = $ClientSecret
}
$params = @{
ContentType = 'application/x-www-form-urlencoded'
Headers = @{'accept'='application/json'}
Body = $Body
Method = 'Post'
URI = $TokenEndpoint
}
$token = Invoke-RestMethod @params
Return "Bearer " + ($token.access_token).ToString()
}
$authResult = getBearer -TenantID $DirectoryID -ClientID $clientID -ClientSecret $secret
$authHeader = @{
'Content-Type'='application/json'
'Accept'='application/json'
'Authorization'= "$authResult"
'x-ms-version' = '2018-03-28'
'Date' = "$(get-date)"
}
$request = "https://Storageaccount.file.core.windows.net/Fileshare?restype=share&comp=stats"
$GetFileShareStatss = Invoke-RestMethod -Uri $request -Headers $authHeader -Method Get
Error : Invoke-RestMethod : AuthenticationFailedServer failed to authenticate the
request. Make sure the value of Authorization header is formed correctly
including the signature.
RequestId:28ef36b0-e01a-009f-3280------------
Time:2020-08-31T10:24:29.4577314ZAuthentication scheme Bearer is not supported.
At line:44 char:23
- ... areStatss = Invoke-RestMethod -Uri $request -Headers $authHeader -Met ...
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:Htt
pWebRequest) [Invoke-RestMethod], WebException
- FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShe
ll.Commands.InvokeRestMethodCommand
Azure storage share rest api : https://video2.skills-academy.com/en-us/rest/api/storageservices/get-share-stats