我目前正在使用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中所有文件的完整文件名。
在这里进一步说明这一点的是我假设的
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中打印结果。
到目前为止,我已经想出了以下代码::
#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) {感谢进一步的帮助/解决方案。
发布于 2013-01-13 03:37:59
免责声明:我没有使用Azure的经验,但是快速查看MSDN文档会让我相信这是可行的:
foreach ($ID in $InputFile)
{
$image_matches = $images | Where-Object {$_.Name -match '^$ID'}
# process matching images here
}https://stackoverflow.com/questions/13158716
复制相似问题