Skip to content

Instantly share code, notes, and snippets.

@jkbryan
Last active October 2, 2018 22:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkbryan/24ce7a41172b028ac1ce6d59bacf29e3 to your computer and use it in GitHub Desktop.
Save jkbryan/24ce7a41172b028ac1ce6d59bacf29e3 to your computer and use it in GitHub Desktop.
clear-adou-attribute.ps1
Import-Module LithnetRMA
# Setup the XPath Query - get all users
$z=New-XPathQuery -AttributeName AccountName -Operator IsPresent
# Use that query in the XPath Expression
$Query=New-XPathExpression -ObjectType Person -QueryObject $z
# Do the search
$Users=Search-Resources -XPath $query -AttributesToGet AccountName, adOU
ForEach ($u in $users)
{
# If adOU is not NULL, then make it so!
If ($u.adOU -ne $NULL)
{
$u.adOU=$NULL
Save-Resource $u
Write-Host $u.AccountName, $u.adOU
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment