Skip to main content

This PowerShell function will get the values that are not empty or null in a hashtable object.

function Get-HashTableNotEmptyOrNullValue
{
    <#
    .SYNOPSIS
        This function will get the values that are not empty or Null in a hashtable object

    .DESCRIPTION
        This function will get the values that are not empty or Null in a hashtable object

    .PARAMETER Hashtable
        Specifies the hashtable that will be showed

    .EXAMPLE
        Get-HashTableNotEmptyOrNullValue -HashTable $SplattingVariable

    .NOTES
        Francois-Xavier Cat
        @lazywinadmin
        lazywinadmin.com

    .LINK
        https://github.com/lazywinadmin/PowerShell/blob/master/TOOL-Get-HashTableNotEmptyValue/Get-HashTableNotEmptyOrNullValue.ps1
    #>
    param(
        [System.Collections.Hashtable]
        $HashTable
    )

    $HashTable.GetEnumerator().name |
    ForEach-Object -Process {
        if ($HashTable[$_] -ne '')
        {
            Write-Output $_
        }
    }
}