Need some help on formatting and displaying more than one result in the proper way.
I am building a function called Get-PageFileInfo . So far I have this and it works as expected for one computer.
Function Get-PageFileInfo
{
[CmdletBinding()]
Param(
[string[]]$ComputerName
)
Get-CimInstance -Class Win32_PageFileUsage -ComputerName $ComputerName |
Select-Object AllocatedBaseSize, Description, Peakusage, TempPageFile
}
That code produces this output:
PS C:\Scripts> Get-PageFileInfo Srv01 AllocatedBaseSize Description Peakusage TempPageFile ----------------- ----------- --------- ------------ 8192 C:\pagefile.sys 203 False
and if i add a second computer, I get this:
PS C:\Scripts> Get-PageFileInfo srvwin0767, crd-dc-wp01 AllocatedBaseSize Description Peakusage TempPageFile ----------------- ----------- --------- ------------ 8192 C:\pagefile.sys 203 False 26624 I:\pagefile.sys 11396 False
Ok, that’s awesome… but I want to add a field called computername and i would like to rename the parameter names. So I thought I would build a PSCUSTOMOBJECT like so:
<pre
$PageFileStats = Get-CimInstance -Class Win32_PageFileUsage -ComputerName $ComputerName |
Select-Object AllocatedBaseSize, Description, Peakusage, TempPageFile
$Results = [PSCustomObject]@{
ComputerName = $ComputerName
PageFileTotalSize = $PageFileStats.AllocatedBaseSize
PageFilePath = $PageFileStats.description
PageFileCurrentUsage = $PageFileStats.CurrentUsage
PageFilePeakUsage = $PageFileStats.Peakusage
TempPageFileInUse = $PageFileStats.TempPageFile
} #END PSCUSTOMOBJECT
$Results
Except that gives me this output:
PS C:\Scripts> Get-PageFileInfo srvwin0767, crd-dc-wp01 | ft
ComputerName PageFileTotalSize PageFilePath PageFileCurrentUsage PageFilePeakUsage TempPageFileInUse
------------ ----------------- ------------ -------------------- ----------------- -----------------
{srvwin0767, crd-dc-wp01} {8192, 26624} {C:\pagefile.sys, I:\pagefile.sys} {$null, $null} {203, 11396} {False, False}
How do I get each member of the aray listed on it’s own line?