【问题标题】:Using Get-AzureStorageFileContent to execute SQL script from Azure Storage file share使用 Get-AzureStorageFileContent 从 Azure 存储文件共享执行 SQL 脚本
【发布时间】:2020-04-18 00:15:22
【问题描述】:

我正在使用 Invoke-Sqlcmd 从 Azure 存储文件共享中获取 -InputFile。我正在使用 Get-AzureStorageFileContent 从 Azure 存储中获取文件,但出现以下错误。感谢您提供任何帮助或见解。

Get-AzureStorageFileContent :远程服务器返回错误:(404) 未找到。 HTTP 状态代码:404 - HTTP 错误消息:指定的资源不存在。 在 line:35 char:1

以下是 Powershell 脚本:

$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

【问题讨论】:

  • Invoke-Sqlcmd 在这里无关紧要。失败的事情Get-AzureStorageFileContent。我建议您编辑标题以反映真正的问题
  • 您是否已经设置了文件共享$azureFileShare
  • @Nick.McDermaid 我已经更新了标题。是的,文件共享已经设置好了。

标签: powershell azure-storage-files invoke-sqlcmd


【解决方案1】:

我从这个链接How can I copy the contents of a .csv file placed in a azure file storage, to a powershell variable?找到了我的问题的答案

我使用 Get-AzureStorageFileContent 将文件下载到 powershell runbook 中的 $evn:temp 文件夹,然后在 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

【讨论】:

    猜你喜欢
    • 2020-10-22
    • 2013-07-04
    • 2018-08-09
    • 2020-09-19
    • 2021-12-21
    • 2020-02-29
    • 1970-01-01
    • 2022-01-07
    • 2021-03-09
    相关资源
    最近更新 更多