widsnet.com
11Jul/120

Test-ADConnection

A simple way to test the connection to AD before running commands.

function Test-ADConnection {
    Try {
        $Connected = $true
        Add-Type -AssemblyName System.DirectoryServices.AccountManagement
        $ct = [System.DirectoryServices.AccountManagement.ContextType]::Domain
        New-Object System.DirectoryServices.AccountManagement.PrincipalContext($ct) | Out-Null
    }
    Catch {
        $Connected = $false
    }
    Return $Connected
}
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

No trackbacks yet.