internal/functions/Resolve-PolicyName.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function Resolve-PolicyName
{
<#
    .SYNOPSIS
        Simple helper tool for parsing GPO object/name input.
     
    .DESCRIPTION
        Simple helper tool for parsing GPO object/name input.
        Returns name or id.
        ONLY use in pipeline.
     
    .PARAMETER InputObject
        The object to parse.
     
    .EXAMPLE
        PS C:\> $Policy | Resolve-PolicyName
     
        Returns IDs or Names of all policy items in $Policy
#>

    [CmdletBinding()]
    param (
        [Parameter(ValueFromPipeline = $true)]
        $InputObject
    )
    
    process
    {
        if ($null -eq $InputObject) { return }
        if ($InputObject.GetType().FullName -eq 'Microsoft.GroupPolicy.Gpo') { return $InputObject.Id -as [string] }
        if ($InputObject.Id) { return $InputObject.Id -as [string] }
        if ($InputObject.DisplayName) { return $InputObject.DisplayName -as [string] }
        $InputObject -as [string]
    }
}