pixel0815
Goto Top

Powershell Suche einen String

Moin!

Ich habe da mal ein "Problem" und frage mich ob sich das auch mit Powershell lösen lässt?
Aus einem Inventory System wie z.B. OCS leite ich die komplette Software via SQL Befehl in eine CSV Datei.
Jetzt ist es ja so, dass der "Computername" natürlich mehrfach / hundertfach vorkommt, weil ja jede Zeile eine Software widerspiegelt. Wenn ich jetzt nach einer bestimmten installierten Software suche, finde ich natürlich z.B. in Excel unproblematisch die Software und dazugehörige Rechner auf denen das gute Stück xyz installiert ist.

Spannend wird das wenn ich jetzt nach einem Softwareprodukt suche und ich die Rechner angezeigt bekommen haben möchte, auf denen die Software NICHT installiert ist.

Der CSV Header ist
 import_device_id;publisher;product;product_version;network;last_inventory;last_contact 

Beispiel Inhalt und ich z.B. soll nach Microsoft Office Standard 2016 geschaut werden.

Test123;Microsoft Corporation;Microsoft Visual C++ 2005 Redistributable;8.0.61001;TEST;18.06.2024 07:56;18.06.2024 07:56
Test123;Microsoft Corporation;Microsoft Visual C++ 2022 X86 Minimum Runtime - 14.36.32532;14.36.32532;TEST;18.06.2024 07:56;18.06.2024 07:56
Test123;Citrix Systems, Inc.;Citrix Receiver (USB);14.12.0.18020;TEST;18.06.2024 07:56;18.06.2024 07:56
Test123;Citrix Systems, Inc.;Self-Service Plug-in;4.12.0.18013;TEST;18.06.2024 07:56;18.06.2024 07:56
Test123;Microsoft Corporation;Microsoft Visual C++ 2013 x86 Minimum Runtime - 12.0.40664;12.0.40664;TEST;18.06.2024 07:56;18.06.2024 07:56
Test123;Microsoft Corporation;Microsoft Visual C++ 2015-2022 Redistributable (x64) - 14.36.32532;14.36.32532.0;TEST;18.06.2024 07:56;18.06.2024 07:56
Test123;Microsoft Corporation;Microsoft Office Standard 2016;16.0.4266.1001;TEST;18.06.2024 07:56;18.06.2024 07:56
Test124;Microsoft Corporation;Microsoft Visual C++ 2005 Redistributable;8.0.61001;TEST;18.06.2024 07:56;18.06.2024 07:56
Test124;Microsoft Corporation;Microsoft Visual C++ 2022 X86 Minimum Runtime - 14.36.32532;14.36.32532;TEST;18.06.2024 07:56;18.06.2024 07:56
Test124;Citrix Systems, Inc.;Citrix Receiver (USB);14.12.0.18020;TEST;18.06.2024 07:56;18.06.2024 07:56
Test124;Citrix Systems, Inc.;Self-Service Plug-in;4.12.0.18013;TEST;18.06.2024 07:56;18.06.2024 07:56
Test124;Microsoft Corporation;Microsoft Visual C++ 2013 x86 Minimum Runtime - 12.0.40664;12.0.40664;TEST;18.06.2024 07:56;18.06.2024 07:56
Test124;Microsoft Corporation;Microsoft Visual C++ 2015-2022 Redistributable (x64) - 14.36.32532;14.36.32532.0;TEST;18.06.2024 07:56;18.06.2024 07:56

Content-ID: 91417350859

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

Ausgedruckt am: 28.09.2024 um 16:09 Uhr

Celiko
Celiko 24.06.2024 aktualisiert um 14:32:26 Uhr
Goto Top
Moin,

du kannst den Inhalt in der Powershell per Import-CSV in eine Variable speichern.
Anschließend kannst du dann filtrieren, was angezeigt werden soll:

$CSV = import-csv -path "C:\csv.csv" -Delimiter ";"  
$CSV | Where-Object {$_.product -like "*Office Standard 2016*"}  

#Ausgabe in einer Tabelle:
$CSV | Where-Object {$_.product -like "*Office Standard 2016*"} | Format-Table  
#Ausgabe in einer Liste:
$CSV | Where-Object {$_.product -like "*Office Standard 2016*"} | Format-List  
#Export in eine neue CSV:
$CSV | Where-Object {$_.product -like "*Office Standard 2016*"} | Export-Csv -Path "C:\CSV_Neu.csv"  

Wenn du wissen willst auf welchen Geräten die Software nicht installiert ist brauchst du eine Variable mit allen Computern (bspw. LDAP Query oder Get-ADComputer). Diese kannst du dann einfach mit deiner $CSV Variable gegenchecken und dir ausgeben lassen, wer die Software noch nicht hat.

Nachtrag: Lösung von TK1987 ist besser 👍

VG
TK1987
Lösung TK1987 24.06.2024 aktualisiert um 15:18:15 Uhr
Goto Top
Moin,

$source = "D:\Test.csv"  
$search = "Microsoft Office Standard 2016"  

$csv = Import-CSV -Path $source -Delimiter ';' -Header import_device_id,publisher,product,product_version,network,last_inventory,last_contact   

# Liste Computer auf, die gesuchte Software nicht enthalten
$csv | Group import_device_id | ?{$search -NotIn $_.Group.Product} | %{$_.import_device_id}

Gruß Thomas

EDIT: CSV-Header auf Vorgabe korrigiert
pixel0815
pixel0815 05.07.2024 um 08:13:26 Uhr
Goto Top
Mega! Das ist eine wirklich gute Lösung. Ich danke dir! Du ahnst nicht wie aufwendig das ist mit Excel oder Power BI umzusetzen.
pixel0815
pixel0815 05.07.2024 um 08:13:47 Uhr
Goto Top
Auch für dich ein herzliches Dankeschön face-smile