1
  • 我正在创建一个用于自动化单调 DB 任务的运行手册。
  • 我的 master.csv 文件每小时更新一次,其中包含我们基础架构中所有资源的详细信息,并放置在 Azure 文件存储系统中。
  • 我正在尝试将资源(DB)的名称作为用户的输入,并通过检查主库存文件来验证它是否存在于我的 Azure 基础架构中。

我主要关心的是我是否能够在变量中获取此 CSV(<100KB) 的内容,以便在后续步骤中使用它进行比较?

我试过下面的代码:

该文件位于{StorageContainer}/a/b/{filename}.csv

  1. $inventory = import-csv {storageaccntname}/a/b/{filename}.csv

  2. $inventory = import-csv https://{storagecontainername}/a/b/{filename}.csv

  3. $inventory = import-csv {随机驱动器号,如 C:,D:,E:}/a/b/{filename}.csv (不要认为这些甚至存在于 azure 文件存储中)

所有导致文件未找到错误。

我还查看了 Get-AzureStorageFileContent 命令,但是这似乎将整个文件下载到了目的地(没有达到目的)。

4

1 回答 1

2

由于 .csv 文件存储在文件共享存储中,您可以使用Get-AzureStorageFileContent将 .csv 文件下载到$evn:temppowershell runbook 中的文件夹中,然后您可以根据需要对 .csv 文件进行操作。

这是一个例子:

假设 azure 文件存储中的文件路径为:(https://xx.file.core.windows.net/a/b/test.csv在此示例中,文件共享名称为“a”)。

在 powershell 运行手册中:

$storageAccountName ="xx"
$storageAccountKey ="xxxxxx"
$context = New-AzureStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey 

# download the test.csv file to the temp folder in runbook
Get-AzureStorageFileContent -ShareName a -Path "b/test.csv" -Destination $env:temp -Context $context

# Then you can do anything to the test.csv file(Note: the file path now is $env:temp\test.csv)

如果还有问题,请告诉我。

于 2019-01-21T02:13:33.533 回答