Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2562

Specify a server during an [ADSI] command

$
0
0
Function Get-ADObjectOU {
# ----------------------------------------------------------------------------------------------
# Function outputs the Objects containing OU
#  - Requires Distinguished Name as input 
#  - Outputs the containing OU
# ----------------------------------------------------------------------------------------------
    Param (
        [parameter(Mandatory=$true, 
        ValueFromPipelineByPropertyName=$true)][alias("dn")][String]$DistinguishedName
    )
    
    $ou = ([ADSI]"LDAP://$DistinguishedName").parent -replace 'LDAP://'
    if( $ou.Length -eq 0 ) {
        Write-Host -ForegroundColor Red "ERROR: Parent OU cannot be found because the DistinguishedName does not exist."
        break
    } else {
        $ou
    }
    
} # End Get-ADObjectOU

I am making several changes just before this where I use "-Server dc.mydomain.com" and replication does not have all controllers up to date for a few seconds.  I want to be sure I am using the same DC that I used to make the changes prior to this command. 

How can I specify the server to use in the above example?


Find this post helpful? Does this post answer your question? Be sure to mark it appropriately to help others find answers to their searches.


Viewing all articles
Browse latest Browse all 2562


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>