Hey Experts. I'm on the 3rd leg of this project and would like to now merge the two scripts I have (thanks to EE) into a single, formidable script (either a batch or powershell).
Script I have for stale computer accounts:
if not exist "%LogFile%" goto SkipRename
for %%f in ("%LogFile%") do (
for /f "tokens=1-3 delims=/ " %%a in ("%%~tf") do (set TimeStamp=%%c%%a%%b)
echo Renaming "%LogFile%" to "!NewName!" ...
ren "%LogFile%" "!NewName!"
ECHO File date: %%~tf
dsquery computer OU=Depts,DC=x -inactive 8 -limit 300 > %logfile%
(for /f "tokens=2,3* delims=,=" %%i in (%logfile%) do @echo %%~i) > c:\tools\staleADPc1.log
Code for stale user accounts:
if exist "%LogFile%" del "%LogFile%"
for /f "delims=" %%a in ('dsquery.exe user "OU=Depts,DC=x" -o samid -limit 0 -inactive 8') do (
>>"%LogFile%" echo %%~a
The two output files can remain as a way of keeping computer and user accounts separate. I've tried doing the merge on my own and the variables have given me enough of a struggle that I'm ready to turn it over to the real experts and learn a little. Thanks for your help with this and providing the necessary script.