这听起来像是一项最简单的任务,我要做的就是列出 Azure 文件存储共享下的子目录的内容,我设法获得了“ CloudFileDirectory ”对象,但是,很难阅读其内容。
我只能在 PowerShell 中编写此解决方案,因此使用名为“AzureRM”的 PS 模块,如下所示:
# Install AzureRM module & check if installed:
Install-Module -Name "AzureRM"
Get-Module -Name AzureRM -List | select Name,Version
# Import module in session:
Import-Module AzureRM
# Connect/sign-on to Azure account (interactive login):
Connect-AzureRmAccount
# Get reference to Storage account:
$storageAcct = Get-AzureRmStorageAccount -ResourceGroupName "myRSG" -AccountName "myCloudStorage"
#Get directory object:
$objDir = Get-AzureStorageFile -Context $storageAcct.Context -ShareName "myShare" -Path "myFolder1"
在这里,我坚持使用这个 ( $objDir ) 对象,它基本上是一个WindowsAzure.Storage.File.CloudFileDirectory对象,但不像通常的目录对象,因为它似乎不包含集合(请参阅下面的输出):
$objDir.GetType().FullName #-> "WindowsAzure.Storage.File.CloudFileDirectory" object
$objDir | % {$_.GetType().FullName} #-> "WindowsAzure.Storage.File.CloudFileDirectory" object
基本上,我需要读取此子文件夹中的文件名。我将不胜感激任何帮助。TIA。
(根据 Gaurav 的评论)管道附加| Get-AzureStorageFile解决了这个问题并返回了预期的输出,即我现在得到一个集合/数组(System.Object[]),我遍历它以获取单个文件名及其各自的大小,这是代码+输出和我现在得到的对象类型:
#Get directory object:
$objDir = Get-AzureStorageFile -Context $storageAcct.Context -ShareName "myShare" -Path "myFolder1" | Get-AzureStorageFile
$objDir.GetType().FullName #-> "System.Object[]" object
$objDir | % {$_.GetType().FullName} #-> "WindowsAzure.Storage.File.CloudFile / CloudDirectory" objects
$objDir | % {$_} | select Name,StreamMinimumReadSizeInBytes
Name StreamMinimumReadSizeInBytes
---- ----------------------------
file.txt 4194304
file1.txt 4194304
foo.txt 4194304
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句