Powershell Script zum verarbeiten verschiedener Values von verschiedenen WMI-Objekten
Hi,
erst einmal: ich bin absoluter Powershell Neuling!
Ich versuche ein Script zu schreiben, das mehrere Values von verschiedenen WMI-Objekten ausgeben soll, z.B.:
Win32_Processor
Caption
Manufacturer
L2CacheSize
NumberofCores
Caption
Manufacturer
L2CacheSize
NumberofCores
Manufacturer
L2CacheSize
NumberofCores
Hierzu habe ich das folgende Script geschrieben. Die Anweisung "Write-Host "Variable j "+ $j" ist nur ein Platzhalter für die weitere Verarbeitung.
Wenn ich das Script laufen lasse, erhalte ich folgenden Output:
Ausgabe bestimmter Werte der WMI-Objekte
WMI-Werte + Microsoft.PowerShell.Commands.Internal.Format.FormatStartData Microsoft.PowerShell.Commands.Internal.Format.GroupStartData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.GroupEndData Microsoft.PowerShell.Commands.Internal.Format.FormatEndData
Variable j + Microsoft.PowerShell.Commands.Internal.Format.FormatStartData
Variable j + Microsoft.PowerShell.Commands.Internal.Format.GroupStartData
Variable j + Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
Variable j + Microsoft.PowerShell.Commands.Internal.Format.GroupEndData
Variable j + Microsoft.PowerShell.Commands.Internal.Format.FormatEndData
WMI-Werte + Microsoft.PowerShell.Commands.Internal.Format.FormatStartData Microsoft.PowerShell.Commands.Internal.Format.GroupStartData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.GroupEndData Microsoft.PowerShell.Commands.Internal.Format.FormatEndData
Variable j + Microsoft.PowerShell.Commands.Internal.Format.FormatStartData
Variable j + Microsoft.PowerShell.Commands.Internal.Format.GroupStartData
Variable j + Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
Variable j + Microsoft.PowerShell.Commands.Internal.Format.GroupEndData
Variable j + Microsoft.PowerShell.Commands.Internal.Format.FormatEndData
WMI-Werte + Microsoft.PowerShell.Commands.Internal.Format.FormatStartData Microsoft.PowerShell.Commands.Internal.Format.GroupStartData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.GroupEndData Microsoft.PowerShell.Commands.Internal.Format.FormatEndData
Variable j + Microsoft.PowerShell.Commands.Internal.Format.FormatStartData
Variable j + Microsoft.PowerShell.Commands.Internal.Format.GroupStartData
Variable j + Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
Variable j + Microsoft.PowerShell.Commands.Internal.Format.GroupEndData
Variable j + Microsoft.PowerShell.Commands.Internal.Format.FormatEndData
Wenn ich das Kommando "Get-WmiObject $i|Format-List -Property $prop" in der Command Line ausführe (Variablen mit Werten ersetzt) funktioniert es prima. In PowerGui hat die Variable $j zur Laufzeit den Wert der oben angezeigt wird.
Vielleicht hat jemand eine Idee.
Vielen Dank im voraus!
RL
$i=0
$wmi_obj_array= "win32_processor", "win32_diskdrive", "win32_operatingsystem"
$w32_proc= "Caption, Manufacturer, L2CacheSize, NumberofCores"
$w32_dd= "DeviceID, Partitions, BytesperSector, TotalSectors"
$w32_os= "Caption, Buildnumber, OSArchitecture, InstallDate"
foreach ($i in $wmi_obj_array)
{
"Ausgewählte WMI-Objekte $i">>c:\PS\WMI_Objekt_Werte.txt
switch ($i){
win32_processor {$prop=$w32_proc}
win32_diskdrive {$prop=$w32_dd}
win32_operatingsystem {$prop=$w32_os}
}
$wmi_value_array=Get-WmiObject $i|Format-List -Property $prop
$j=0
Write-Host "WMI-Werte" + $wmi_werte_array
foreach ($j in $wmi_werte_array)
{
Write-Host "Variable j "+ $j }
}
Ausgabe bestimmter Werte der WMI-Objekte
WMI-Werte + Microsoft.PowerShell.Commands.Internal.Format.FormatStartData Microsoft.PowerShell.Commands.Internal.Format.GroupStartData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.GroupEndData Microsoft.PowerShell.Commands.Internal.Format.FormatEndData
Variable j + Microsoft.PowerShell.Commands.Internal.Format.FormatStartData
Variable j + Microsoft.PowerShell.Commands.Internal.Format.GroupStartData
Variable j + Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
Variable j + Microsoft.PowerShell.Commands.Internal.Format.GroupEndData
Variable j + Microsoft.PowerShell.Commands.Internal.Format.FormatEndData
WMI-Werte + Microsoft.PowerShell.Commands.Internal.Format.FormatStartData Microsoft.PowerShell.Commands.Internal.Format.GroupStartData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.GroupEndData Microsoft.PowerShell.Commands.Internal.Format.FormatEndData
Variable j + Microsoft.PowerShell.Commands.Internal.Format.FormatStartData
Variable j + Microsoft.PowerShell.Commands.Internal.Format.GroupStartData
Variable j + Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
Variable j + Microsoft.PowerShell.Commands.Internal.Format.GroupEndData
Variable j + Microsoft.PowerShell.Commands.Internal.Format.FormatEndData
WMI-Werte + Microsoft.PowerShell.Commands.Internal.Format.FormatStartData Microsoft.PowerShell.Commands.Internal.Format.GroupStartData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.GroupEndData Microsoft.PowerShell.Commands.Internal.Format.FormatEndData
Variable j + Microsoft.PowerShell.Commands.Internal.Format.FormatStartData
Variable j + Microsoft.PowerShell.Commands.Internal.Format.GroupStartData
Variable j + Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
Variable j + Microsoft.PowerShell.Commands.Internal.Format.GroupEndData
Variable j + Microsoft.PowerShell.Commands.Internal.Format.FormatEndData
Wenn ich das Kommando "Get-WmiObject $i|Format-List -Property $prop" in der Command Line ausführe (Variablen mit Werten ersetzt) funktioniert es prima. In PowerGui hat die Variable $j zur Laufzeit den Wert der oben angezeigt wird.
Vielleicht hat jemand eine Idee.
Vielen Dank im voraus!
RL
Please also mark the comments that contributed to the solution of the article
Content-Key: 195267
Url: https://administrator.de/contentid/195267
Printed on: May 4, 2024 at 08:05 o'clock
1 Comment
Hallo,
versuchs mal hiermit:
das $i=0 kannst du weglassen hat irgendwie kein Sinn
und die 2. Schleife habe ich weggelassen, die hat für mich keinen Sinn ergeben.
Wenn noch Fragen offen sind, helfe ich gerne weiter
Der Torsten wars
versuchs mal hiermit:
[array]$wmi_obj_array= "win32_processor", "win32_diskdrive", "win32_operatingsystem"
[array]$w32_proc= "Caption", "Manufacturer", "L2CacheSize", "NumberofCores"
[array]$w32_dd= "DeviceID", "Partitions", "BytesperSector", "TotalSectors"
[array]$w32_os= "Caption", "Buildnumber", "OSArchitecture", "InstallDate"
foreach ($i in $wmi_obj_array)
{
"Ausgewählte WMI-Objekte $i">>$home\WMI_Objekt_Werte.txt
switch ($i){
win32_processor {[array]$prop=$w32_proc}
win32_diskdrive {[array]$prop=$w32_dd}
win32_operatingsystem {[array]$prop=$w32_os}
}
$wmi_value_array=Get-WmiObject -class $i |select $prop
Write-Host "WMI-Werte"
$wmi_value_array | Format-List
das $i=0 kannst du weglassen hat irgendwie kein Sinn
und die 2. Schleife habe ich weggelassen, die hat für mich keinen Sinn ergeben.
Wenn noch Fragen offen sind, helfe ich gerne weiter
Der Torsten wars