我目前正在使用Powershell腳本來管理Windows Azure中的BlobStorage內容。我想要一個讀取文本文件內容的腳本,並在BlobStorage中顯示以此內容開頭的文件名稱。我正在尋找一個通配符搜索,其中列出了BlobStorage中的名稱,該名稱以文本文件中指定的內容開始。檢查BlobStorage中以Powershell中的字符串開頭的文件名
我想到了一個循環,它搜索文本文件中的每一行,並查找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文件名的文本文件,並顯示全BlobStorage中包含此ID的所有文件的文件名。
要指定這進一步這裏就是我是假設:
foreach (ID in textfile)
{
files = find files in BlobStorage with name that starts with ID (ListBlobsWithPrefix?)
foreach (textfile in files)
{
Write filename to console
}
}
到目前爲止,我已經設法使我的blobstorage連接和它的作品,我可以在圖像容器列出斑點的名字。我已經檢查過,所有內容都可以通過閱讀文本文件並將內容打印到控制檯。我沒有設法做的是將文本文件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) {
願聞其幫助/解決方案。
是您的代碼清單是否正確?它是否應該以不完整的循環結束? – Rytmis