如何将放置在 azure 文件存储中的 .csv 文件的内容复制到 powershell 变量?
How can I copy the contents of a .csv file placed in a azure file storage, to a powershell variable?
- 我正在创建一个用于自动化单调数据库任务的运行手册。
- 我的 master.csv 文件每小时更新一次,包含我们基础架构中所有资源的详细信息,并放置在 Azure 文件存储系统中。
- 我正在尝试将资源 (DB) 的名称作为用户的输入,并通过检查主清单文件来验证它是否存在于我的 Azure 基础架构中。
我主要担心的是我是否能够在变量中获取此 CSV 的内容 (<100KB),以便在后续步骤中使用它进行比较?
我试过下面的代码:
文件位于 {StorageContainer}/a/b/{filename}.csv
$inventory = import-csv {storageaccntname}/a/b/{filename}.csv
$inventory = import-csv https://{storagecontainername}/a/b/{filename}.csv
$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)
如果还有问题,请告诉我。
- 我正在创建一个用于自动化单调数据库任务的运行手册。
- 我的 master.csv 文件每小时更新一次,包含我们基础架构中所有资源的详细信息,并放置在 Azure 文件存储系统中。
- 我正在尝试将资源 (DB) 的名称作为用户的输入,并通过检查主清单文件来验证它是否存在于我的 Azure 基础架构中。
我主要担心的是我是否能够在变量中获取此 CSV 的内容 (<100KB),以便在后续步骤中使用它进行比较?
我试过下面的代码:
文件位于 {StorageContainer}/a/b/{filename}.csv
$inventory = import-csv {storageaccntname}/a/b/{filename}.csv
$inventory = import-csv https://{storagecontainername}/a/b/{filename}.csv
$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)
如果还有问题,请告诉我。