首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >检查BlobStorage中以Powershell中的字符串开头的文件名

检查BlobStorage中以Powershell中的字符串开头的文件名
EN

Stack Overflow用户
提问于 2012-10-31 13:08:34
回答 1查看 1.6K关注 0票数 2

我目前正在使用Powershell脚本来管理Windows中的BlobStorage内容。我想要一个脚本来读取文本文件的内容,并在BlobStorage中显示以该内容开头的文件名。我正在寻找一个通配符搜索,它列出了BlobStorage中的名称,从文本文件中指定的内容开始。

我想到了一个循环,它搜索文本文件中的每一行,并在BlobStorage中查找以文本文件中指定内容开头的文件名。

*例如,如果文本文件中有2行*

43345-sdfssd-42342-sdfsf

32423-asdsad-23424-dghfs

BlobStorage中的文件名是

43345-sdfssd-42342-sdfsf-250.PNG

43345-sdfssd-42342-sdfsf-650.PNG

92323-asadad-12342-sdfds-1600.PNG

我希望将文本文件中的ID与BlobStorage文件的名称进行比较,并显示包含此ID的BlobStorage中所有文件的完整文件名。

在这里进一步说明这一点的是我假设的

代码语言:javascript
复制
foreach (ID in textfile) 
{                           

  files = find files in BlobStorage with name that starts with ID (ListBlobsWithPrefix?)

  foreach (textfile in files) 
  {                
            Write filename to console
  }

}

到目前为止,我已经成功地连接到我的Blobs存储,并且它可以工作,我可以在图像容器中列出Blobs的名称。我已经检查了所有的工作,以及读取文本文件和打印内容到控制台。我没有成功地将文本文件ID与BlobStorage中的Blob文件名进行比较,并在以ID开头的BlobStorage中打印结果。

到目前为止,我已经想出了以下代码:

代码语言:javascript
复制
#Make a connection to my BlobStorage
$SAN = "XX"
$SAK="X"

$creds = New-Object Microsoft.WindowsAzure.StorageCredentialsAccountAndKey($SAN, $SAK)
$client = New-Object      Microsoft.WindowsAzure.StorageClient.CloudBlobClient("https://$SAN.blob.core.windows.net",$creds)

$bro = New-Object Microsoft.WindowsAzure.StorageClient.BlobRequestOptions
$bro.UseFlatBlobListing = $true

#Add $images blobcontainer and use flatbloblisting to list blobnames
$imagecontainer = $client.GetBlobDirectoryReference("images")
$images = $imagecontainer.ListBlobs($bro)

#Add textfile and assign it to a variable
$InputFile = Get-Content C:\transcript\hej.txt

#Loop to find everything in the input file and compare it to matching filenames in  blobstorage. Return filenames that starts with the ID/contains the ID in the inputfile.
foreach ($ID in Get-Content $InputFile) {

感谢进一步的帮助/解决方案。

EN

回答 1

Stack Overflow用户

发布于 2013-01-13 03:37:59

免责声明:我没有使用Azure的经验,但是快速查看MSDN文档会让我相信这是可行的:

代码语言:javascript
复制
foreach ($ID in $InputFile)
{
    $image_matches = $images | Where-Object {$_.Name -match '^$ID'}

    # process matching images here
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13158716

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档