ankhmorpork
Goto Top

Systemdaten auslesen mit Powershell

Hallo zusammen,

oft werden Fragen zu Problemen gestellt, ohne das betroffene System hinreichend vorzustellen. Keine Lust, keine Ahnung, keine Zeit ...
Mit einem kleinen Script ist das schnell erledigt, das System hält die Daten ja vor. Ich habe mal ein Powershell-Script zusammengestellt, das diese Aufgabe schnell und unkompliziert erledigt:

<# MyMachine.ps1
Systemdaten abfragen (via WMI-Objekte) ... auch remote möglich ... Bildschirmausgabe ... 
Ausgabe in Datei schreiben: .\MyMachine.ps1 > "MachineData.txt"  
#>

Param
(
[String]$Computer = "LocalHost"  # entspricht $Computer = "."  
)

$Line = "`n" # Zeilenumbruch schreiben  

Function Get-ComputerInfo
{
$Line + "COMPUTER:"  
"---------"  
# collect computer data:
$colItems = Get-WmiObject -class win32_ComputerSystem -Computername $Computer

Foreach($objItem in $colItems)
{
"Manufacturer         : " + $objItem.Manufacturer  
"Model                : " + $objItem.Model  
"Name                 : " + $objItem.Name  
"Domain               : " + $objItem.Domain  
"Number of processors : " + $objItem.NumberOfProcessors  
"Physical memory      : " + [Math]::Round($objItem.TotalPhysicalMemory/1GB, 2) + " GB"  
"System type          : " + $objItem.SystemType  
$Line
} #ForEach
} #Function


Function Get-DiskInfo
{
$Line + "DISK:"  
"-----"  
# collect disk data:
$colItems = Get-WmiObject -class win32_DiskDrive -Computername $Computer

ForEach($objItem in $colItems)
{
"Manufacturer         : " + $objItem.Manufacturer  
"Model                : " + $objItem.Model  
"Disk name            : " + $objItem.Name  
"Mediatype            : " + $objItem.MediaType  
"Partitions           : " + $objItem.Partitions  
"Size                 : " + [Math]::Round($objItem.Size/1GB,2) + " GB"  
$Line
} #ForEach
} #Function


Function Get-GraphicsInfo
{
$Line + "GRAPHICS:"  
"---------"  
# collect grafics data:
$colItems = Get-WmiObject -class cim_PCVideoController -Computername $Computer

ForEach($objItem in $colItems)
{
"Name                 : " + $objItem.Name  
"Resolution horizontal: " + $objItem.CurrentHorizontalResolution + " pixels"  
"Resolution vertical  : " + $objItem.CurrentVerticalResolution + " pixels"  
"Refresh rate         : " + $objItem.CurrentRefreshRate + " Hz"  
$Line
} #ForEach
} #Function


Function Get-ProcessorInfo
{
$line + "PROCESSOR:"  
"----------"  
# collect processor data
$colItems = Get-WmiObject -class win32_Processor -Computername $Computer

ForEach($objItem in $colItems)
{
"Manufacturer         : " + $objItem.Manufacturer  
"Name                 : " + $objItem.Name.Trim()  
"Version              : " + $objItem.Version  
"Clock speed          : " + $objItem.CurrentClockSpeed + " Hz"  
"Voltage              : " + $objItem.CurrentVoltage + " V"  
"Data width           : " + $objItem.Datawidth + " bit"  
"Number of cores      : " + $objItem.NumberOfCores  
"Logical Processors   : " + $objItem.NumberOfLogicalProcessors  
$Line
} #ForEach
} #Function


Function Get-OSInfo
{
$Line + "OPERATING SYSTEM:"  
"-----------------"  
# collect OS data
$colItems = Get-WmiObject -class win32_OperatingSystem -Computername $Computer

ForEach($objItem in $colItems)
{
"Manufacturer         : " + $objItem.Manufacturer  
"Name                 : " + $objItem.Name  
"Version              : " + $objItem.Version  
"Build number         : " + $objItem.BuildNumber  
"Build type           : " + $objItem.BuildType  
"Code set             : " + $objItem.CodeSet  
"System directory     : " + $objItem.SystemDirectory  
"Total virtual memory : " + [Math]::Round($objItem.TotalVirtualMemorySize/1MB,2) + " MB"  
"Serial number        : " + $objItem.SerialNumber  
$Line
} #ForEach
} #Function


Function Get-BiosInfo
{
$Line + "BIOS:"  
"-----"  
# collect BIOS data
$colItems = Get-WmiObject -class win32_Bios -Computername $Computer

ForEach($objItem in $colItems)
{
"Manufacturer         : " + $objItem.Manufacturer  
"Name                 : " + $objItem.Name  
"Serial number        : " + $objItem.SerialNumber  
$Line
} #ForEach
} #Function


Function Get-NetworkInfo
{
$Line + "NETWORK:"  
"--------"  
# collect network data (only if available)
$colItems = Get-WmiObject Win32_NetworkAdapterConfiguration -Computername $Computer | where{$_.IPEnabled -eq "True"}  

ForEach($objItem in $colItems)
{
"Description         :" + $objItem.Description  
"DHCP enabled        :" + $objItem.DHCPEnabled  
"DHCP server         :" + $objItem.DHCPServer  
"IP address          :" + $objItem.IPAddress  
"Sub net mask        :" + $objItem.IPSubnet  
"Dafault gateway     :" + $objItem.DefaultIPGateway  
"DNS domain          :" + $objItem.DNSDomain  
"DNS host            :" + $objItem.DNSHostName  
"MAC address         :" + $objItem.MACAddress  
$Line
} #ForEach
} #Function


# and here we go
Get-ComputerInfo
Get-DiskInfo
Get-GraphicsInfo
Get-ProcessorInfo
Get-OSInfo
Get-BiosInfo
Get-NetworkInfo

Vielleicht kann damit jemand etwas anfangen. Die abgefragten Daten lassen sich natürlich fast beliebig erweitern.

[Edit]: Remote-Fähigkeit angepasst (Parameter, default = ".")


Gruß

ANKH

Content-Key: 230288

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

Printed on: April 24, 2024 at 05:04 o'clock

Member: colinardo
colinardo Feb 18, 2014 updated at 16:44:00 (UTC)
Goto Top
Hi ANKH,
schönes Schnippselchen face-smile
als Ergänzung für die Leute die hier vorbei schauen, noch ein Link zu einem Script das das ganze schön aufbereitet in einem Excel-Sheet zusammenfasst und auch automatisiert für mehrere Rechner im Netzwerk macht:
Powershell Skripten, Netzwerk auslesen

Grüße Uwe
Member: AnkhMorpork
AnkhMorpork Feb 19, 2014 at 06:59:37 (UTC)
Goto Top
Hallo Uwe,

man dankt!
"Schnippselchen" passt ganz gut. War eigentlich mehr eine Art Fingerübung und natürlich nicht für den professionellen Gebrauch gedacht. Da passen deine Links deutlich besser.
Ich dachte da eher an die kurze und schmerzlose Zusammenfassung von Elementarinfos z.B. hier im Forum. Ausserdem wollte ich auch mal etwas zurückgeben, nachdem mir hier schon derart gut geholfen wurde. Wenn es wem nützt ... und sei es nur als Anregung.
Ich habe damit meine Distanzstrategie zur PS aufgeben können.

Ich mache mich dann mal auf den Weg zum angehenden Halb-Semiprofi.

Gruß

ANKH