Lets say I want to do the very simple query in AD
dsquery user -name "John Smith" | dsget user -memberof -expand
This will output the DNs of the AD groups that this user belongs to. I can make it print the friendly group name via:
dsquery user -name "John Smith" | dsget user -memberof -expand | dsget group -samid
However if a group has a hash tag in it (e.g. "CN=#Kentucky Office,OU=#Distribution Lists,DC=myenterprise,DC=local") will fail with the following error:
dsget failed:Value for 'Target object for this command' has incorrect format.
The way to fix this is to unescape the hashes (i.e. "CN=#Kentucky Office,OU=#Distribution Lists,DC=myenterprise,DC=local"). I can do this in powershell via the oneliner:
dsquery user -name "John Smith" | dsget user -memberof -expand | ForEach-Object { $_.Replace('\#', '#') } | dsget group -samid
Is there a solution that does not involve powershell.exe or even adding an executable to the pipe besides dsquery or dsget?