Private/_PopulateGenericDataGrid.ps1

function _PopulateGenericDataGrid {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]
        [ValidateSet('Software', 'Updates', 'Processes', 'Services')]
        [string]$LookupType,

        [Parameter(Mandatory = $true)]
        [string]$Identity
    )
    $Object = @()
    switch ($LookupType) {
        # TODO if computer is not reachable, notify in the datagrid
        'Software' {
            $SoftwareListing = _GetInstalledSoftware -Identity $Identity | Sort-Object Name
            foreach ($Software in $SoftwareListing) {
                $Object += [PSCustomObject]@{
                    InstallDate      = $Software.InstallDate
                    Name             = $Software.Name
                    Version          = $Software.Version
                    UninstallCommand = $Software.UninstallCommand
                }
            }
            $GenericDataGrid.Title = 'Installed Software'
        }
        'Updates' {
            $Updates = _GetInstalledUpdates -Identity $Identity | Select-Object Title, Date, Description, Operation | Sort-Object Date -Descending
            foreach ($Update in $Updates) {
                $Object += [PSCustomObject]@{
                    Date        = $Update.Date
                    Title       = $Update.Title
                    Operation   = $Update.Operation
                    Description = $Update.Description
                }
            }
            $GenericDataGrid.Title = 'Installed Updates'
        }
        'Processes' {
            $ScriptBlock = { Get-Process -IncludeUserName }
            try {
                if ($Identity -eq $env:COMPUTERNAME) {
                    $Processes = Invoke-Command -ScriptBlock $ScriptBlock -ErrorAction Stop
                }
                else {
                    $Processes = Invoke-Command -ComputerName $Identity -ScriptBlock $ScriptBlock -ErrorAction Stop
                }
            }
            catch {
                $Object += [PSCustomObject]@{
                    Error = 'Unable to get processes'
                }
                break
            }
            foreach ($Process in ($Processes | Sort-Object CPU -Descending)) {
                $Object += [PSCustomObject]@{
                    'Process Name' = $Process.ProcessName
                    'CPU Usage'    = $Process.CPU
                    # TODO make this show in KB or something
                    'Memory Usage' = $Process.PrivateMemorySize
                    Path           = $Process.Path
                    User           = $Process.UserName
                    ID             = $Process.ID
                }
            }
            $GenericDataGrid.Title = 'Running Processes'
        }
        'Services' {
            $ScriptBlock = { Get-Service }
            try {
                if ($Identity -eq $env:COMPUTERNAME) {
                    $Services = Invoke-Command -ScriptBlock $ScriptBlock -ErrorAction Stop
                }
                else {
                    $Services = Invoke-Command -ComputerName $Identity -ScriptBlock $ScriptBlock -ErrorAction Stop
                }
            }
            catch {
                $Object += [PSCustomObject]@{
                    Error = 'Unable to get services'
                }
                break
            }
            foreach ($Service in ($Services | Sort-Object Name)) {
                $Object += [PSCustomObject]@{
                    Name                 = $Service.Name
                    'Display Name'       = $Service.DisplayName
                    Status               = $Service.Status
                    'Start Type'         = $Service.StartType
                    'Dependent Services' = if ($Service.DependentServices) {
                        $Service.DependentServices.Name | _OutSingleStringFromArray
                    }
                }
            }
            $GenericDataGrid.Title = 'Running Services'
        }
        Default {
        }
    }
    $GenericDataGrid_DataGrid.ItemsSource = $Object
}