私は現在、Windows Azure で BlobStorage コンテンツを管理するために Powershell スクリプトを使用しています。テキスト ファイルのコンテンツを読み取り、このコンテンツで始まる 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
}
}
これまでのところ、ブロブストレージへの接続を確立することができましたが、うまくいきました。イメージ コンテナー内のブロブの名前を一覧表示できます。テキストファイルの読み取りとコンテンツのコンソールへの出力ですべてが機能することを確認しました。私ができなかったのは、テキストファイル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) {
さらなるヘルプ/解決策に感謝します。