如何将放置在 azure 文件存储中的 .csv 文件的内容复制到 powershell 变量?

How can I copy the contents of a .csv file placed in a azure file storage, to a powershell variable?

我主要担心的是我是否能够在变量中获取此 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 命令,但这似乎是将整个文件下载到目的地(没有达到目的)。

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

这是一个例子:

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

在 powershell runbook 中:

$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)

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