1

I am using Invoke-Sqlcmd to pick up -InputFile from an Azure Storage File share. I am using the Get-AzureStorageFileContent to get the file from Azure Storage but getting the error below. Any help or insight is appreciated.

Get-AzureStorageFileContent : The remote server returned an error: (404) Not Found. HTTP Status Code: 404 - HTTP Error Message: The specified resource does not exist. At line:35 char:1

Below is the Powershell script:

$ctx = New-AzureStorageContext -StorageAccountName $azureStorageAccount -StorageAccountKey $storageKey
Get-AzureStorageFileContent -ShareName $azureFileShare -Path $azureFilePath -Destination $destination -Context  $ctx 
# Set Connection parameters
$params = @{
    'Database' = $Database
    'ServerInstance' = $ServerInstance
    'Username' = $dbusername
    'Password' = $dbpassword
    'InputFile' = $ctx+'\'+$scriptFile

}

Invoke-Sqlcmd @params
cenko
  • 43
  • 7
  • `Invoke-Sqlcmd` is irrelevant here. The thing that is failing `Get-AzureStorageFileContent`. I suggest you edit your title to reflect the real issue – Nick.Mc Apr 18 '20 at 05:09
  • Have you already set up the file share `$azureFileShare`? – Nick.Mc Apr 18 '20 at 05:12
  • @Nick.McDermaid I have updated the title. And yes, the file share is already set up. – cenko Apr 20 '20 at 14:54

1 Answers1

0

I found the answer to my question from this link How can I copy the contents of a .csv file placed in a azure file storage, to a powershell variable?

I used Get-AzureStorageFileContent to download the file to the $evn:temp folder in powershell runbook, then used it in the Invoke-Sqlcmd.

Get-AzureStorageFileContent -ShareName $azureFileShare -Path $azureFilePath -Destination $env:temp -Context $context

# Set Connection parameters
$params = @{
    'Database' = $Database
    'ServerInstance' = $ServerInstance
    'Username' = $dbusername
    'Password' = $dbpassword
    'InputFile' = $env:temp

}

Invoke-Sqlcmd @params
cenko
  • 43
  • 7