如何将放置在蔚蓝文件存储中的.csv文件的内容复制到powershell变量? [英] How can I copy the contents of a .csv file placed in a azure file storage, to a powershell variable?

查看:100
本文介绍了如何将放置在蔚蓝文件存储中的.csv文件的内容复制到powershell变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我主要担心的是,是否可以在变量中获取此CSV(< 100KB)的内容,以便在后续步骤中将其用于比较?

My main concern is if I will be able to get the contents of this CSV(<100KB) in a variable so that I use it for comparison in the subsequent step?

我尝试了以下代码:

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

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

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

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

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

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

$inventory = import-csv {random drive letters like C:,D:,E:}/a/b/{filename}.csv (Don't think these even exist for an azure file storage)

所有导致找不到文件的错误.

All resulting in file not found error.

我也看过Get-AzureStorageFileContent命令,但这似乎是将整个文件下载到一个目的地(没有用).

I also had a look at the Get-AzureStorageFileContent command however this seems to download the whole file at a destination (doesn't serve the purpose).

推荐答案

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

Since the .csv file is stored in the file share storage, you can use Get-AzureStorageFileContent to download the .csv to the $evn:temp folder in powershell runbook, then you can operate the .csv file as per your need.

这里是一个例子:

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

Assume the file path in azure file storage is: https://xx.file.core.windows.net/a/b/test.csv (in this example, the file share name is "a").

在Powershell Runbook中:

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

请让我知道是否还有其他问题.

Please let me know if any more issues.

这篇关于如何将放置在蔚蓝文件存储中的.csv文件的内容复制到powershell变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆