batch files: getting information from your Windows AD
Posted by jpluimers on 2011/10/13
If you have the Windows Server Resource Kit tools installed, then dsget and dsquery can get you some valuable information about the current user and computer.
Below is a sample batch file that shows that dsquery
gets you [Wayback/Archive] DNs, and dsget
gets you detailed information for a certain type of DN.
You can use pipes (and sometimes you need to [Wayback/Archive] escape the pipes) to pass information from dsquery
to dsget
.
dsget
will happily accept multiple DNs (each on a new line), so you can use text-files with DNs too.
@echo on :: this assumes that dsquery, dsget, etc are in the same directory as the batch file ::escape pipe with caret for /f "tokens=* delims= " %%a in ('%~dp0dsquery user -samid %USERNAME% ^| %~dp0dsget user -desc ^| find /V "dsget succeeded"') do ( set description=%%a ) ::trim last two spaces if "%description:~-2%"==" " set description=%description:~0,-2% echo !%description%!
–jeroen
Get the full exe path name of running processes. « The Wiert Corner – irregular stream of stuff said
[…] second batch file escapes the pipe (|) by using a carret (^), so it is passed from the command-line to […]