lupora
Goto Top

Mit Powershell CSV auslesen und Metaproperty ändern

Hallo zusammen,

ich schreibe aktuell ein Script und bräuchte ein wenig Hilfe :/

Ich habe eine CSV welche wie folgt aufgebaut ist:

Spalte A = Bildname
Spalte B = Merkmal1
Spalte C = Merkmal2
Spalte D = Merkmal3

Die Logik des Scriptes soll auf Azure alle Dateien (Blobs) eines Storage Accounts durch iterieren.
Immer wenn es ein Bild findet, soll es kurz prüfen ob es den Namen des Bildes (sind alle unique) in der CSV findet.
Falls ja, soll es die Merkmale (aus der CSV) an das Bild dran hängen. Die Azure Logik hab ich schon fertig gebaut. Aber die Logik, welche die CSV durchsucht fehlt mir noch :/

So schaut die Azure Logik aus (gekürzt)

 foreach($blob in $blobs)  
    {  
            az storage blob metadata update --name $blob.Name --metadata $metadata
    }  

Aktuell ist $metadata noch statisch. Im Falle das er zum Bild auf Azure einen Eintrag in der CSV findet, würde die Variable so ausschauen:
$metadata ="Merkmal1, Merkmal2, Merkmal3"

Ich habe folgendes aktuell:
Import-Csv .\bilder.csv | ForEach-Object {

if ($_.bildname -eq $blob.Name) {
$metadata = "$_.merkmal1, $_.merkmal2, $_.merkmal3"  
az storage blob metadata update --name $blob.Name --metadata $metadata

} Else {
   write-host "nothing found"  
}

}
Gefühlt müssten es zwei ineinander geschachtelte Foreach Schleifen sein. Aber hab das jetzt nach ewigem hin und her einfach nicht zum laufen bekommen :/
Freue mich über Hilfe face-smile

Content-Key: 666986

Url: https://administrator.de/contentid/666986

Printed on: April 23, 2024 at 21:04 o'clock

Member: mayho33
mayho33 May 21, 2021 updated at 22:37:04 (UTC)
Goto Top
Zitat von @Lupora:
> 
> Import-Csv .\bilder.csv | ForEach-Object {
> 
> if ($_.bildname -eq $blob.Name) {
> $metadata = "$_.merkmal1, $_.merkmal2, $_.merkmal3"  
> az storage blob metadata update --name $blob.Name --metadata $metadata
> 
> } Else {
>    write-host "nothing found"  
> }
> 
> }
> 

Hi!

Mach aus deinem
$metadata mal ein Array

 $metadata = @($_.merkmal1, $_.merkmal2, $_.merkmal3)

Und arbeite dann mit einer weiteren Foreach.