Use the script in the link I provided, then load it as part of your profile, or convert it to a powershell module and load the module as part of your script then you can use those functions to convert in your own scripts.
On Sat, Nov 15, 2014 at 12:03 AM, Aakash Shah <aakash.s...@uci.edu> wrote: > Thanks for pointing me to the System.DirectoryServices namespace. I’ll > read more into that to see if it can help with this. > > > > Thanks, > > > > -Aakash Shah > > > > *From:* listsad...@lists.myitforum.com [mailto: > listsad...@lists.myitforum.com] *On Behalf Of *Michael B. Smith > *Sent:* Thursday, November 13, 2014 6:21 AM > *To:* powershell@lists.myitforum.com > *Subject:* [powershell] RE: Search For OU Using Filter With CanonicalName > in AD > > > > You can speed this up quite a bit by using .NET (in the > System.DirectoryServices namespace) – which is almost certainly what the > QAD cmdlets do – but you are always going to be limited by the fact that > CanonicalName is a constructed attribute. > > > > *From:* listsad...@lists.myitforum.com [ > mailto:listsad...@lists.myitforum.com <listsad...@lists.myitforum.com>] *On > Behalf Of *Aakash Shah > *Sent:* Wednesday, November 12, 2014 11:24 PM > *To:* powershell@lists.myITforum.com > *Subject:* [powershell] RE: Search For OU Using Filter With CanonicalName > in AD > > > > Thanks for the information. I came across that while I was researching > into this, but I was hoping that there would be a better way to > convert/search for this with the newer versions of Powershell/AD cmdlets > (the posted solution is 6 years old). > > > > Thanks, > > > > -Aakash Shah > > > > *From:* listsad...@lists.myitforum.com [ > mailto:listsad...@lists.myitforum.com <listsad...@lists.myitforum.com>] *On > Behalf Of *Damien Solodow > *Sent:* Wednesday, November 12, 2014 8:03 PM > > *To:* powershell@lists.myitforum.com > *Subject:* [powershell] RE: Search For OU Using Filter With CanonicalName > in AD > > > > Perhaps something like this: http://poshcode.org/512 > http://poshcode.org/512 ? > > > > DAMIEN SOLODOW > > Systems Engineer > > 317.447.6033 (office) > > 317.447.6014 (fax) > > HARRISON COLLEGE > ------------------------------ > > *From:* listsad...@lists.myitforum.com [listsad...@lists.myitforum.com] > on behalf of Aakash Shah [aakash.s...@uci.edu] > *Sent:* Wednesday, November 12, 2014 10:48 PM > *To:* powershell@lists.myITforum.com > *Subject:* [powershell] RE: Search For OU Using Filter With CanonicalName > in AD > > If I have the canonical name “domain.com/OU”, I am looking for a way to > convert this into its corresponding DN value of “OU=OU,DC=domain,DC=com”. > I plan to then use this to feed other cmdlets like Get-ADUser where the > -SearchBase parameter appears to expect a DN value. > > > > In my earlier email, I was attempting to search AD for the canonical name > using the “-Filter” parameter in Get-ADOrganizationalUnit since it appears > to have CanonicalName as an attribute, but I was unsuccessful. > > > > My apologies for the confusion. > > > > Thank you, > > > > -Aakash Shah > > > > *From:* listsad...@lists.myitforum.com [ > mailto:listsad...@lists.myitforum.com <listsad...@lists.myitforum.com>] *On > Behalf Of *Michael B. Smith > *Sent:* Wednesday, November 12, 2014 7:27 PM > *To:* powershell@lists.myitforum.com > *Subject:* [powershell] RE: Search For OU Using Filter With CanonicalName > in AD > > > > I don’t understand what you are asking for. Please give an example… > > > > *From:* listsad...@lists.myitforum.com [ > mailto:listsad...@lists.myitforum.com <listsad...@lists.myitforum.com>] *On > Behalf Of *Aakash Shah > *Sent:* Wednesday, November 12, 2014 9:59 PM > *To:* powershell@lists.myITforum.com > *Subject:* [powershell] Search For OU Using Filter With CanonicalName in > AD > > > > Is there a clean/efficient way to filter for a canonical name in AD? I > tried the following but it did not work: > > > > Get-ADOrganizationalUnit -Filter 'CanonicalName -eq "domain.com/OU"' > -Properties 'CanonicalName' > > > > When I looked up other solutions, I found some sources where the string is > parsed and manually pieced together as a DN entry, but I would like to > avoid that preferably. I was able to previously do this with the Quest > cmdlets but I am working on moving away from them and am trying to find > equivalent approaches, if possible. > > > > I can pipe Get-ADOrganizationalUnit to a Where cmdlet to then do a > search, but it is much slower: > > > > Get-ADOrganizationalUnit -Filter * -Properties 'CanonicalName' | > Where-Object {$_.CanonicalName -eq 'domain.com/OU'} > > > > Or, if anyone has information on using built in commands to convert a > canonical name to a DN value, that would also be appreciated (the solutions > I found also manually pieced each block together). > > > > Thanks, > > > > -Aakash Shah > > > > > ================================================ > Did you know you can also post and find answers on PowerShell in the > forums? > http://www.myitforum.com/forums/default.asp?catApp=1 > > > ================================================ > Did you know you can also post and find answers on PowerShell in the > forums? > http://www.myitforum.com/forums/default.asp?catApp=1 > > > ================================================ > Did you know you can also post and find answers on PowerShell in the > forums? > http://www.myitforum.com/forums/default.asp?catApp=1 > > > ================================================ > Did you know you can also post and find answers on PowerShell in the > forums? > http://www.myitforum.com/forums/default.asp?catApp=1 > > > ================================================ > Did you know you can also post and find answers on PowerShell in the > forums? > http://www.myitforum.com/forums/default.asp?catApp=1 > > > ================================================ > Did you know you can also post and find answers on PowerShell in the > forums? > http://www.myitforum.com/forums/default.asp?catApp=1 > > ================================================ > Did you know you can also post and find answers on PowerShell in the > forums? > http://www.myitforum.com/forums/default.asp?catApp=1 > -- Isaac Holmes IT Engineering Specialist University of Notre Dame 320 IT Center Notre Dame, IN 46556 (574) 631-3254 ================================================ Did you know you can also post and find answers on PowerShell in the forums? http://www.myitforum.com/forums/default.asp?catApp=1