troubleshooting Question

if then inside for loop not working - Batch scripting

Avatar of Antonio King
Antonio King asked on
Windows Batch
8 Comments1 Solution164 ViewsLast Modified:
Hi
I have created a batch script that adjusts folder ownership and permissions. The script recursively cycles through all subfolders names of a folder. The names of the folders are usernames. The script assigns folder ownership and full permissions to the that user. Ie. If the folder name is "JBloggs", then Jbloggs will be made the owner and be granted full permission.

There is one folder I do not want the script to touch. This folder is called "default"

I've added an IF then NEQ statement so if it encounters a folder with the name "default" it will just skip over it, but it doesn't seem to be working.

Any advice would be greatly appreciated!

@ECHO OFF
SETLOCAL enabledelayedexpansion

CD /D "D:\Public\Users\"
FOR /D %%A IN (*) DO (
	IF %%A NEQ "default" THEN (
REM		TAKEOWN /F "%%A" /A /R /D Y
REM		ICACLS "%%A" /RESET /T
REM		ICACLS "%%A" /GRANT:R "DOMAIN\%%A:(OI)(CI)F"
REM		ICACLS "%%A" /SETOWNER "DOMAIN\%%A" /T
		ECHO %%A >> C:\Public\Scripts\Log.txt
	)
)
ENDLOCAL
EXIT
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros