Skip to content

Instantly share code, notes, and snippets.

@doublenns
Created August 30, 2017 16:49
Show Gist options
  • Save doublenns/9b1b048a753f2a20fe54858f2ba5b9f8 to your computer and use it in GitHub Desktop.
Save doublenns/9b1b048a753f2a20fe54858f2ba5b9f8 to your computer and use it in GitHub Desktop.
Retrieve Active Directory Organizational Unit for machine and only display if matches w/ specified parameter
param([string]$env="DEV")
$computers = Get-Content Documents\servers.txt
Foreach ($server in $computers){
$ou_result = ([adsisearcher]"(&(name=$server)(objectClass=computer))").findall().path
echo $ou_result | Select-String -Pattern $env -NotMatch
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment