$output.'AvailableDriveSpace (GB)' = Get-CimInstance -ComputerName $server -ClassName Win32_LogicalDisk |
Select-Object -Property DeviceID,@{Name='FreeSpace';Expression={ [Math]::Round(($_.Freespace / 1GB),1) }}

运行我构建的脚本时,我会获得所有正确的信息,但如下所示
Processor                : Intel(R) Core(TM) i5-7500 CPU @ 3.40GHz
OperatingSystem          : Microsoft Windows 10 Pro
AvailableDriveSpace (GB) : {@{DeviceID=C:; FreeSpace=4.9}, @{DeviceID=D:; FreeSpace=0}, @{DeviceID=H:; FreeSpace=194.7}, @{DeviceID=S:; FreeSpace=215.6}}
RAM (GB)                 : 8
UserProfileSize (GB)     : 17

任何想法,我如何使它更加用户友好:)

最佳答案

这完全取决于您认为是更用户友好的输出。

也许您正在追求这样的事情?

$output = [PsCustomObject]@{
    'Processor'       = (Get-CimInstance -ClassName Win32_Processor -ComputerName $Computer).Name -replace '\s+', ' '
    'OperatingSystem' = (Get-CimInstance -ClassName Win32_OperatingSystem -ComputerName $Computer).Caption.Trim()

    'AvailableDriveSpace (GB)' = (Get-CimInstance -ClassName Win32_LogicalDisk -ComputerName $Computer | ForEach-Object {
        'DeviceID = {0}  FreeSpace = {1}' -f $_.DeviceId, [Math]::Round(($_.Freespace / 1GB),1)
    } ) -join ([Environment]::NewLine)

    # get the user name who last logged on. The Where-Object clause filters out
    # NT AUTHORITY\SYSTEM, NT AUTHORITY\LOCAL SERVICE etc.
    'LastLogOn' = (Get-CimInstance -ClassName Win32_NetworkLoginProfile -ComputerName $Computer |
                   Where-Object { $_.Name -notlike 'NT AUTHORITY*' } |
                   ForEach-Object {
        'UserName = {0}  LastLogon = {1}' -f $_.Name, $_.LastLogon
    } ) -join ([Environment]::NewLine)

}
$output | fl *

结果:

关于powershell - PC库存Powershell,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59358638/

10-13 07:50