My goal is to have A message displayed for Active, Inactive, and Disabled accounts would have their user directory deleted if Not found or Disabled.
This is not focusing on the user profiles, just user file directories left behind by others named with their domain credentials.
So far I'm getting ERRORLEVEL 0 on *everything*, even on strings were the domain user query is returned as "Active: No".
Code: Select all
@ECHO OFF
Dir c:\Users\ /B > C:\temp\Users_data.txt
for /F "tokens=*" %%A in (C:\temp\Users_data.txt) do (
ECHO Processing %%A....
net user /domain %%A > C:\temp\User_status.txt
@findstr -sip "Account active Yes" C:\temp\User_status.txt >NULL
ECHO ERRORLEVEL :%ERRORLEVEL%
IF %ERRORLEVEL% EQU 0 echo User %%A is Active!!
@findstr -sip "Account active No" C:\temp\User_status.txt >NULL
ECHO ERRORLEVEL :%ERRORLEVEL%
IF %ERRORLEVEL% EQU 0 echo User %%A is NOT Active!! User might be on LOA! Delete?
@findstr -sip "The user name could not be found." C:\temp\User_status.txt >NULL
ECHO ERRORLEVEL :%ERRORLEVEL%
IF %ERRORLEVEL% EQU 0 echo User could not be Found, data will be deleted!
REM rd d:\LocalData\%%A /s /q
ECHO .
)
REM del C:\temp\Users_data.txt
REM del C:\temp\User_status.txt
Pause
Any help would be appreciated.