SystemInfo

Elsőre úgy tűnhet, hogy a SystemInfo eszközzel könnyű dolgunk lesz, hiszen itt is van /FO CSV lehetőség arra, hogy CSV kimenetet kapjunk, csakhogy itt bizonyos tulajdonságok is összetett objektumok, és ennek ábrázolására a CSV nem igazán alkalmas. Nézzünk, elsőre mit kapunk:

PS C:\> systeminfo /FO CSV | ConvertFrom-Csv

                                                                             

 

Host Name                 : STLENO

OS Name                   : Microsoft Windows 10 Enterprise

OS Version                : 10.0.10586 N/A Build 10586

OS Manufacturer           : Microsoft Corporation

OS Configuration          : Standalone Workstation

OS Build Type             : Multiprocessor Free

Registered Owner          : Tibi

Registered Organization   :

Product ID                : 00329-10280-00000-AA724

Original Install Date     : 2015.12.19., 3:49:15

System Boot Time          : 2015.12.31., 9:02:08

System Manufacturer       : LENOVO

System Model              : 20378

System Type               : x64-based PC

Processor(s)              : 1 Processor(s) Installed.,[01]: Intel64 Family 6 M

                            odel 60 Stepping 3 GenuineIntel ~2300 Mhz

BIOS Version              : LENOVO 9ECN40WW(V3.00), 2015.07.22.

Windows Directory         : C:\WINDOWS

System Directory          : C:\WINDOWS\system32

Boot Device               : \Device\HarddiskVolume1

System Locale             : hu;Hungarian

Input Locale              : hu;Hungarian

Time Zone                 : (UTC+01:00) Belgrade, Bratislava, Budapest, Ljublj

                            ana, Prague

Total Physical Memory     : 16 300 MB

Available Physical Memory : 11 970 MB

Virtual Memory: Max Size  : 32 684 MB

Virtual Memory: Available : 27 812 MB

Virtual Memory: In Use    : 4 872 MB

Page File Location(s)     : C:\pagefile.sys

Domain                    : WORKGROUP

Logon Server              : \\MicrosoftAccount

Hotfix(s)                 : 4 Hotfix(s) Installed.,[01]: KB3116278,[02]: KB312

                            4200,[03]: KB3132372,[04]: KB3133431

Network Card(s)           : 4 NIC(s) Installed.,[01]: VirtualBox Host-Only Eth

                            ernet Adapter,      Connection Name: VirtualBox Ho

                            st-Only Network,      DHCP Enabled:    No,      IP

                             address(es),      [01]: 192.168.56.1,      [02]:

                            fe80::c8fb:ea3d:fdec:6e50,[02]: Realtek PCIe GBE F

                            amily Controller,      Connection Name: Ethernet,

                                 Status:          Media disconnected,[03]: Int

                            el(R) Dual Band Wireless-AC 7260,      Connection

                            Name: Wireless Network Connection,      DHCP Enabl

                            ed:    Yes,      DHCP Server:     192.168.0.1,

                              IP address(es),      [01]: 192.168.0.101,      [

                            02]: fe80::9102:50db:a167:cc6f,[04]: Bluetooth Dev

                            ice (Personal Area Network),      Connection Name:

                             Bluetooth Network Connection 2,      Status:

                                 Media disconnected

Hyper-V Requirements      : VM Monitor Mode Extensions: Yes,Virtualization Ena

                            bled In Firmware: Yes,Second Level Address Transla

                            tion: Yes,Data Execution Prevention Available: Yes

Távolról nézve szépnek tűnik a kimenet, de a részletekben már láthatók a hiányosságok. Elsőként a dátumok nem igazi dátumok (pl.: System Boot Time). A különböző memóriaértékek nem igazi számértékek. A hotfixek sem alkotnak igazi gyűjteményt, de az igazi kavarodás a hálózati kártyáknál van.

Ha közelíteni szeretnénk a kapott eredményeket a PowerShellben megszokott objektum-alapú kimenetekhez, akkor még további feldolgozásra van szükségünk, erre azonban nincs beépített kapcsoló. A következő függvény egy első közelítés lehet:

function Get-SystemInfo {

    $obj = systeminfo /FO CSV | ConvertFrom-Csv

    $obj."Original Install Date" = [datetime] ($obj."Original Install Date" -replace ",","")

    $obj."System Boot Time" = [datetime] ($obj."System Boot Time" -replace ",","")

 

    $memoryprops = Get-Member -InputObject $obj -MemberType NoteProperty -Name *memory* |

        Select-Object -ExpandProperty Name

 

    foreach($p in $memoryprops){

        $obj.$p = Invoke-Expression ($obj.$p -replace "(?<=\d).+(?=\d)|\s","")

    }

    $obj.'Hotfix(s)' = $obj.'Hotfix(s)' -split "," | Select-Object -Skip 1 |

        ForEach-Object {$_ -replace "\[\d+\]: ",""}

 

    $netinfo = $obj.'Network Card(s)' -split "," | Select-Object -Skip 1

    $obj.'Network Card(s)' = @()

    $netobj = $null

    for($i = 0; $i -lt $netinfo.count; $i++){

        switch -regex ($netinfo[$i]){

            "^\[\d+\]: " {

                            if($netobj){

                                $obj.'Network Card(s)' += $netobj

                            }

                            $name = $_ -replace "^\[\d+\]: ",""

                            $netobj = New-Object -TypeName PSObject -Property @{

                                    Name = $name

                                }

                            continue

                        }

            "^\s+\w+[^:]*:\s+"  {

                                if($_ -match "^\s+(?<propname>\w+[^:]*):\s+(?<propvalue>.*)"){

                                    Add-Member -InputObject $netobj -MemberType NoteProperty -Name $matches.propname -Value $matches.propvalue

                                }

                                continue

                            }

            "^\s+[^:]+$"    {

                                if($_ -match "^\s+(?<multivalueprop>[^:]+)$"){

                                    $propname = $matches.multivalueprop

                                    Add-Member -InputObject $netobj -MemberType NoteProperty -Name $propname -Value @()

                                }

                                $i++

                                while($i -lt $netinfo.count){

                                    if($netinfo[$i] -match "\s+\[\d+\]:\s+(?<multivalue>.*)"){

                                        $netobj.$propname += $matches.multivalue

                                        $i++

                                    }

                                    else{

                                        $i--

                                        break

                                    }

                                }

                            }

            }

    }

    if($netobj){

        $obj.'Network Card(s)' += $netobj

    }

 

    $HyperVObj = New-Object -TypeName PSObject

    $obj.'Hyper-V Requirements' -split "," | ForEach-Object {

        $propname, $propvalue = $_ -split ": "

        Add-Member -InputObject $HyperVObj -MemberType NoteProperty -Name $propname -Value $propvalue

    }

    $obj.'Hyper-V Requirements' = $HyperVObj

 

    $obj

}

Ha ezt futtatjuk, akkor a kimenet a következő lesz:

PS C:\> $info = Get-SystemInfo

PS C:\> $info

 

 

Host Name                 : STLENO

OS Name                   : Microsoft Windows 10 Enterprise

OS Version                : 10.0.10586 N/A Build 10586

OS Manufacturer           : Microsoft Corporation

OS Configuration          : Standalone Workstation

OS Build Type             : Multiprocessor Free

Registered Owner          : Tibi

Registered Organization   :

Product ID                : 00329-10280-00000-AA724

Original Install Date     : 2015.12.19. 3:49:15

System Boot Time          : 2015.12.31. 9:02:08

System Manufacturer       : LENOVO

System Model              : 20378

System Type               : x64-based PC

Processor(s)              : 1 Processor(s) Installed.,[01]: Intel64 Family 6 M

                            odel 60 Stepping 3 GenuineIntel ~2501 Mhz

BIOS Version              : LENOVO 9ECN40WW(V3.00), 2015.07.22.

Windows Directory         : C:\WINDOWS

System Directory          : C:\WINDOWS\system32

Boot Device               : \Device\HarddiskVolume1

System Locale             : hu;Hungarian

Input Locale              : hu;Hungarian

Time Zone                 : (UTC+01:00) Belgrade, Bratislava, Budapest, Ljublj

                            ana, Prague

Total Physical Memory     : 10485760

Available Physical Memory : 18874368

Virtual Memory: Max Size  : 35651584

Virtual Memory: Available : 29360128

Virtual Memory: In Use    : 48234496

Page File Location(s)     : C:\pagefile.sys

Domain                    : WORKGROUP

Logon Server              : \\MicrosoftAccount

Hotfix(s)                 : {KB3116278, KB3124200, KB3132372, KB3133431}

Network Card(s)           : {@{Name=VirtualBox Host-Only Ethernet Adapter; Con

                            nection Name=VirtualBox Host-Only Network; DHCP En

                            abled=No; IP address(es)=System.Object[]}, @{Name=

                            Realtek PCIe GBE Family Controller; Connection Nam

                            e=Ethernet; Status=Media disconnected}, @{Name=Int

                            el(R) Dual Band Wireless-AC 7260; Connection Name=

                            Wireless Network Connection; DHCP Enabled=Yes; DHC

                            P Server=192.168.0.1; IP address(es)=System.Object

                            []}, @{Name=Bluetooth Device (Personal Area Networ

                            k); Connection Name=Bluetooth Network Connection 2

                            ; Status=Media disconnected}}

Hyper-V Requirements      : @{VM Monitor Mode Extensions=Yes; Virtualization E

                            nabled In Firmware=Yes; Second Level Address Trans

                            lation=Yes; Data Execution Prevention Available=Ye

                            s}

Bár elsőre nem tűnik ez sem túl szépnek, de ha mélyebbre ásunk, akkor kiderülnek a szépségek, például az első hálózati kártya adatai:

PS C:\> $info.'Network Card(s)'[0] | fl *

 

 

Name            : VirtualBox Host-Only Ethernet Adapter

Connection Name : VirtualBox Host-Only Network

DHCP Enabled    : No

IP address(es)  : {192.168.56.1, fe80::c8fb:ea3d:fdec:6e50}

Vagy a HyperV adatok:

PS C:\> $info.'Hyper-V Requirements' | fl *

 

 

VM Monitor Mode Extensions          : Yes

Virtualization Enabled In Firmware  : Yes

Second Level Address Translation    : Yes

Data Execution Prevention Available : Yes

A következő lépés az lehetne, hogy format.xml formátmokat definiálunk a különböző egyedi objektumokhoz, így nem kell a fl * használatával alakítani a kinézetet.

 

 



Word To HTML Converter