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:
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
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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<# 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
Bitte markiere auch die Kommentare, die zur Lösung des Beitrags beigetragen haben
Content-ID: 230288
Url: https://administrator.de/knowledge/systemdaten-auslesen-mit-powershell-230288.html
Ausgedruckt am: 01.04.2025 um 19:04 Uhr
2 Kommentare
Neuester Kommentar
Hi ANKH,
schönes Schnippselchen
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
schönes Schnippselchen
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