Alan's Blog

"Yeah. I wrote a script that will do that."

Menu
  • About My Blog
Menu

Get Distinguished Name of Many computers in PowerShell (Revised)

Posted on February 15, 2014November 29, 2014 by Alan

Getting the DN for an individual computer is not a difficult task in PowerShell, ex:

Import-Module activedirectory                                                                            
$(Get-ADComputer $env:COMPUTERNAME).distinguishedName                                                    



									

Doing this fast for a long list of machines in a big forest is less easy.  Get-ComputerDN.ps1 gets the distinguished name of a list of computers using WorkFlows. I spent some time trying out how to figure out the best way to do Active Directory Global Catalog searches in an Active Directory forest with many domains, such as level2.level1.root.com.  I don’t want to query root.com when I know that the computer account exists under level1.root.com.  Similarly, I don’t want to query outside my domain, level2.levels1.root.com when I know the computer account exists there.

What this script did for me was to get some hands on with parallel processing using workflows and  to help me to decide how I want to manage Global Catalog queries in the future.  The original version of this script looked pinged the computer name and looked for the DN.  This version is much more sophisticated.  If you give it a list of NetBIOS names it will figure out the FQDN based on the LDAP query.  It will figure out the closest Global Catalog Server for the domain you are querying by using the ping response time.  I am using ParameterSetName to manage the choice of the domain level to query.  You can see from the commented code I default to the forest, but let the user select the current domain or the parent domain.  I also accept either a computer name or a file path as input. Unlike prior versions, the script will always ping the computer even if it is not in AD.  It requires PS Version 3.

Updated: 1/30/14 to fix ping problems. 2/15/14 major rewrite.

Leave a Reply

You must be logged in to post a comment.

Search

Please Note

All the scripts are saved as .txt files. Newer files have a “View Script” button which will let you save or open a script in notepad. For earlier posts, the easiest way to download with IE is to right click on the link and use “Save Target As”. Rename file from Name_ext.txt to Name.ext.

To see a full post after searching, please click on the title.

PowerShell Scripts were written with version 3 or later.

https connections are supported.

All new users accounts must be approved, as are comments. Please be patient.  If you find a post error or a script which doesn’t work as expected, I appreciate being notified.  My email is my first name at the domain name, and you are welcome to contact me that way.

Tags

1E ACLS Active Directory ActiveDirectory ADSI Advanced Functions Audit Change Administrator Password COMObject Computer Groups DateTime Desktop DNS Excel FileScriptingObject Forms General GPO GPS Group Policy Hacks ISE Lockout logons NAV740 Nessus OU OU permissions Outlook Pick Folder Power PowerShell Powershell Scriptlets RDP SCCM schedule reboot Scripting Security Shell.Application user information VBA Windows Update WMI WordPress WPF

Categories

akaplan.com

  • Back to Home Page

Archives

Scripting Sites

  • A Big Pile of Small Things
  • Adam, the Automator
  • Art of the DBA
  • Ashley McGlone
  • Boe Prox
  • Carlo Mancini
  • DexterPOSH
  • Doug Finke
  • Jaap Brasser's Blog
  • JeffOps The Scripting Dutchman
  • Jonathan Medd's Blog
  • Keith Hill's Blog
  • LazyWinAdmin
  • Nana Lakshmanan
  • PowerShell Magazine
  • PowerShell Team Blog
  • PowerShell.org
  • PwrShell.net
  • Richard Siddaway's Blog
  • Ryan Yates' Blog
  • Skatterbrainz
  • The Lonely Administrator

SQL Site

  • Art of the DBA

Meta

  • Register
  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
©2025 Alan's Blog | Theme by SuperbThemes

Terms and Conditions - Privacy Policy