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 | Select-Object InstallDate, Name, Version, UninstallCommand | Sort-Object Name
            $Object += [PSCustomObject]$SoftwareListing
            $GenericDataGrid.Title = 'Installed Software'
        }
        'Updates' {
            $Updates = _GetInstalledUpdates -Identity $Identity | Select-Object Title, Date, Description, Operation | Sort-Object Date -Descending
            $Object += [PSCustomObject]$Updates
            $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
            }
            # display the CPU and memorysize in appropriate measurements
            $Object += [PSCustomObject]$Processes | Select-Object ProcessName, CPU, @{n="Memory (KB)";e={[math]::Round($_.PrivateMemorySize/1KB,2)}}, Path, UserName, ID | Sort-Object CPU -Descending
            $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
            }
            $Object += [PSCustomObject]$Services = $Services | Select-Object Name, DisplayName, Status, StartType, @{Name = 'Dependent Services'; Expression = { if ($_.DependentServices.Name) {
                        $_.DependentServices.Name | _OutSingleStringFromArray
                    } }
            }
            $GenericDataGrid.Title = 'Running Services'
        }
        Default {
        }
    }
    $GenericDataGrid_DataGrid.ItemsSource = $Object
}