ActiveDirectory/ServerRake.ActiveDirectory.Read.ps1

#########################################
### ACTIVEDIRECTORY FUNCTIONS: READ ###
#########################################

# ALL FUNCTIONS WILL NEED TO RUN FROM A JUMPHOST IMPORT THE ACTIVEDIRECTORY MODULE

function Get-ADCOs {

    [CmdletBinding()]
    param (

        [Parameter(Mandatory = $true)]
        [String[]] $ComputerName

    )

    if (!$secret -AND !$secretPlain) {

        throw "No secret sessions are currently opened. Start a session with 'Open-SecretSession' and try again."
    
    } elseif (!$jh) {

        throw "Double-Hop session is required for file copy. Use 'Open-DoubleHopSession' to connect with a jumphost on the server's network and try again."

    }

    $response = Invoke-Command -Session $jh -ArgumentList $secret, $ComputerName -ScriptBlock {
    
        param ($secret, $ComputerName)

        Import-Module ActiveDirectory -WarningAction SilentlyContinue

        $domainController = ([System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().FindDomainController()).Name

        $results = @()
        $results += $ComputerName | % {Get-ADComputer -Identity $_ -Server $domainController -Properties * -Credential $secret}

        return $results

    }

    return $response

}

function Get-ADComputerObjectPath {
    
    [CmdletBinding()]
    param (

        [Parameter(Mandatory = $true)]
        [String[]] $ComputerName

    )

    $COs = Get-ADCOs -ComputerName $ComputerName

    $response = @()
    foreach ($co in $COs) {

        $response += [PSCustomObject]@{

            Server                  =   $co.Name
            "AD CO Location"        =   $co.CanonicalName

        }
    
    }

    return $response

}