ankhmorpork
Goto Top

Systemdaten auslesen mit Powershell 7.0

Moin,

da hier fast alle Systeme heruntergefahren sind, kommt man u.U. auf abwegige Gedanken - so auch hier.

Ich habe vor ca. 100 Jahren folgendes Skript hier veröffentlicht:
Systemdaten auslesen mit Powershell

In Zeiten von (nein, nicht das schlimme Wort!) PS 7.0 habe ich das mal angepasst. Damit ist es auch für Linux und macOS nutzbar.
Here we go:

$Line = "`n" # Zeilenumbruch schreiben  

Function Get-ComputerInfo
{
$Line + "COMPUTER:"  
"---------"  
# collect computer data:
$colItems = Get-CimInstance CIM_ComputerSystem

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-CimInstance CIM_DiskDrive

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-CimInstance CIM_PCVideoController

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-CimInstance CIM_Processor

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-CimInstance CIM_OperatingSystem

ForEach($objItem in $colItems)
{
"Architecture         : " + $objItem.OSArchitecture  
"Manufacturer         : " + $objItem.Manufacturer  
"Name                 : " + $objItem.Name  
"Version              : " + $objItem.Version  
"Build number         : " + $objItem.BuildNumber  
"Build type           : " + $objItem.BuildType  
"Code set             : " + $objItem.CodeSet  
"Date of installation : " + $objItem.InstallDate.ToString()  
"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-CimInstance CIM_BiosElement

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-CimInstance win32_NetworkAdapterConfiguration | 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


Virenfreie Grüße von

Ankh


P.S.: Munter bleiben!

Content-Key: 558724

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

Printed on: April 19, 2024 at 04:04 o'clock

Member: Penny.Cilin
Penny.Cilin Mar 17, 2020 at 09:28:01 (UTC)
Goto Top
moin, tach, gude

wie auch immer. face-wink

dös ist doch nur 6 Jahre her. Also aus den 2010er.
Wenn es wenigstens aus dem letzten Jahrtausend gewesen wäre, dann ok.

Trotzdem vielen Dank. Und ein Herzchen von mir dazu. face-smile

Gruss Penny.
Member: AnkhMorpork
AnkhMorpork Mar 17, 2020 at 09:43:46 (UTC)
Goto Top
Zeitdilatation???
Mitglied: 143728
143728 Apr 19, 2020 updated at 14:42:55 (UTC)
Goto Top
Moin.
Damit ist es auch für Linux und macOS nutzbar.
Hmm. Get-CimInstance unter Linux/Mac?? Da gibt es doch überhaupt keinen WMI Unterbau ...

c.
Member: tech-flare
tech-flare Jun 14, 2020 at 07:48:09 (UTC)
Goto Top
Zitat von @143728:

Moin.
Damit ist es auch für Linux und macOS nutzbar.
Hmm. Get-CimInstance unter Linux/Mac?? Da gibt es doch überhaupt keinen WMI Unterbau ...

c.

Hast du auch Powershell für Linux / Mac vorher installiert?

Linux:
docs.microsoft.com/de-de/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-7

MacOS:
docs.microsoft.com/de-de/powershell/scripting/install/installing-powershell-core-on-macos?view=powershell-7
Mitglied: 144260
144260 Jun 14, 2020 updated at 08:22:41 (UTC)
Goto Top
Zitat von @tech-flare:

Zitat von @143728:

Moin.
Damit ist es auch für Linux und macOS nutzbar.
Hmm. Get-CimInstance unter Linux/Mac?? Da gibt es doch überhaupt keinen WMI Unterbau ...

c.

Hast du auch Powershell für Linux / Mac vorher installiert?

Linux:
docs.microsoft.com/de-de/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-7

MacOS:
docs.microsoft.com/de-de/powershell/scripting/install/installing-powershell-core-on-macos?view=powershell-7

Es gibt kein WMI unter Linux, deswegen gibt es die Befehle dort auch nicht
https://petri.com/5-things-to-know-about-powershell-core-on-linux

No WMI or CIM

First, many Windows PowerShell scripters are used to using commands like Get-WmiObject or Get-CimInstance to retrieve management information. 
There are also a number of commands that rely on WMI under the hood like Restart-Computer. In the PowerShell Core world on Linux, these commands don’t exist. 
The reason is simple: there is no CIM infrastructure on Linux platforms. This isn’t a defect in PowerShell, just a recognition of the platform. In much the same way, there is no Get-Service command on Linux because it doesn’t have “services” in the Windows sense. Now, this doesn’t mean all hope is lost. There is a long-term solution in play that involves OMI (Open Management Infrastructure). If you do a web search for “linux omi”, you’ll find a number of results, including references to Microsoft’s plans regarding OMI and Linux. Once these bits are in place, the CIM story will change but for now, you’ll have to live without it.

https://www.heise.de/developer/artikel/PowerShell-7-0-Funktionsumfang-46 ...
Unter Linux und macOS fehlen alle PowerShell-Module, die nicht zum Kern der PowerShell, sondern zu Windows gehören. So findet man unter Linux und macOS lediglich 270 Befehle statt der 1507 Befehle auf Windows 10.