Reputation: 6615
The following code to harvest distinguished name works on all my computers but a few.
FOR /F "skip=2 tokens=3*" %%I in ('reg query "hklm\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine" /v Distinguished-Name') DO @ECHO "%%I %%J"
I am looking into one XP machine that is exhibiting this, and tried alternatives like the one below to no avail:
FOR /F "tokens=3*" %%I in ('reg query "hklm\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine" /v Distinguished-Name |findstr "CN="') DO ECHO "%%I %%J"
Interestingly, I get the results just fine if I do not include for /f like this:
reg query "hklm\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine" /v Distinguished-Name |findstr "CN="
Distinguished-Name REG_SZ CN=xyz123,OU=Test-5,DC=test,DC=com
or
reg query "hklm\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine" /v Distinguished-Name
! REG.EXE VERSION 3.0
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine
Distinguished-Name REG_SZ CN=xyz123,OU=Test-5,DC=test,DC=com
Any ideas what may be going on here?
Upvotes: 0
Views: 238
Reputation: 37569
FOR /F "tokens=2*" %%I in ('reg query "hklm\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine" /v Distinguished-Name^|find "REG_SZ"') DO ECHO "%%J"
This works with all Windows versions.
Upvotes: 1
Reputation: 6615
Duh! I took that part out of script and forgot to remove '%' so that it should have been %I instead of %%I, which is why nothing was returned.
Upvotes: 0