Public/Get-DomainAndForestMode.ps1

Function Get-DomainAndForestMode {
    <#
        .Synopsis
            Shows Domain and Forest modes
        .Description
            Shows Domain and Forest modes, usefull for administrative purpose or if you're looking to upgrade to a higher domain/forest level.
        .Parameter AuthType
            Specifies the authentication method to use.
 
            The acceptable values for this parameter are:
 
            Negotiate or 0
            Basic or 1
            The default authentication method is Negotiate.
 
            A Secure Sockets Layer (SSL) connection is required for the Basic authentication method.
        .Parameter Credential
            Specifies the user account credentials to use to perform this task.
 
            The default credentials are the credentials of the currently logged on user unless the cmdlet is run from an Active Directory module for Windows PowerShell provider drive.
            If the cmdlet is run from such a provider drive, the account associated with the drive is the default.
 
            To specify this parameter, you can type a user name such as User1 or Domain01\User01, or you can specify a PSCredential object.
            If you specify a user name for this parameter, the cmdlet prompts for a password.
 
            You can also create a PSCredential object by using a script or by using the Get-Credential cmdlet. You can then set the Credential parameter to the PSCredential object.
            If the acting credentials do not have directory-level permission to perform the task, the command returns a terminating error.
        .Parameter Identity
            Specifies an Active Directory forest object by providing one of the following attribute values.
 
            The identifier in parentheses is the Lightweight Directory Access Protocol (LDAP) display name for the attribute.
            All values are also for the domainDNS object that represents the domain.
 
            The acceptable values for this parameter are:
 
            A fully qualified domain name
            A GUID (objectGUID)
            A DNS host name
            A NetBIOS name
            The cmdlet searches the default naming context or partition to find the object. If two or more objects are found, the cmdlet returns a non-terminating error.
 
            This parameter can also get this object through the pipeline or you can set this parameter to a forest object instance.
        .Parameter Current
            Specifies whether to return the domain of the local computer or the current logged on user. The acceptable values for this parameter are:
 
            LocalComputer or 0
            LoggedOnUser or 1
        .Parameter Server
            Specifies the Active Directory Domain Services instance to connect to, by providing one of the following values for a corresponding domain name or directory server. The service may be any of the following: Active Directory Lightweight Domain Services, Active Directory Domain Services or Active Directory snapshot instance.
 
            Specify the Active Directory Domain Services instance in one of the following ways:
 
            Domain name values:
 
            Fully qualified domain name
            NetBIOS name
            Directory server values:
 
            Fully qualified directory server name
            NetBIOS name
            Fully qualified directory server name and port
            The default value for this parameter is determined by one of the following methods in the order that they are listed:
 
            By using the Server value from objects passed through the pipeline
            By using the server information associated with the Active Directory Domain Services Windows PowerShell provider drive, when the cmdlet runs in that drive
            By using the domain of the computer running Windows PowerShell
        .Example
            Get-DomainAndForestMode
            Shows Domain and Forest modes
        .Inputs
            None
        .LINK
            about_functions_advanced
        .LINK
            about_CommonParameters
    #>

    [CmdletBinding(
        HelpURI = 'https://cstekelenburg.visualstudio.com/JBOSCollection/_wiki/wikis/JBOADS?pagePath=Get-DomainAndForestMode'
    )]
    [OutputType('JBOADS.Domain.Forest.Mode.Info')]
    Param(
        [ValidateSet("Basic", "1", "Negotiate", "0")]
        [Microsoft.ActiveDirectory.Management.ADAuthType]$AuthType = "Negotiate",
        [PSCredential][System.Management.Automation.Credential()]$Credential,
        [String]$Identity,
        [String]$Current,
        [String]$Server
    )
    Begin {
        If (-not $PSBoundParameters.ContainsKey('Verbose')) {
            $VerbosePreference = $PSCmdlet.SessionState.PSVariable.GetValue('VerbosePreference')
        }
        If (-not $PSBoundParameters.ContainsKey('ErrorAction')) {
            $ErrorActionPreference = $PSCmdlet.SessionState.PSVariable.GetValue('ErrorActionPreference')
        }
    }
    Process {
        Try {
            Write-Verbose ('{0}:: Collecting data from domain' -f $MyInvocation.MyCommand)
            $domainmode = Get-ADDomain @PSBoundParameters

            Write-Verbose ('{0}:: Collecting data from forest' -f $MyInvocation.MyCommand)
            $forestmode = Get-ADForest @PSBoundParameters

            $properties = @{
                PSTypeName  = 'JBOADS.Domain.Forest.Mode.Info'
                NetBIOSName = $domainmode.NetBIOSName
                PDCEmulator = $domainmode.PDCEmulator
                DomainMode  = $domainmode.DomainMode
                ForestMode  = $forestmode.ForestMode
            }
        } Catch {
            Write-Warning ($_.Exception.Message + " : " + $_.Exception.GetType().Fullname)

            $properties = @{
                PSTypeName  = 'JBOADS.Domain.Forest.Mode.Info'
                NetBIOSName = $null
                PDCEmulator = $null
                DomainMode  = $null
                ForestMode  = $null
            }
        } Finally {
            $OutputObject = New-Object -TypeName PSObject -Property $properties
        }
    }
    End {
        Write-Output $OutputObject
    }
}
Set-Alias -Name Show-DomainAndForestMode -Value Get-DomainAndForestMode -Description "Get Domain and Forest Mode" -Option ReadOnly -PassThru -ErrorAction SilentlyContinue