Batch Getting user name from Active Directory using SID?

  active-directory, batch-file, for-loop, sid, windows

The following script makes a backup of the data of each user’s windows profile as long as each user has a folder in the backup location :

@echo off

set Target=D:backup

for /f "tokens=*" %%I in ('dir /a:d-h /b "%SystemDrive%Users*"') do if exist "%Target%%%~nXI" (

........

)

pause 
exit

I need to change the logon name of one user. After changing it in the Active Directory, the user’s profile folder (C:Users) keeps the old name.

From what I understand : the SID is linked to AD account and changing username and other properties are without effect on user’s windows profile.

I’m wondering if there is a way to get the new name in batch from its SID ? If yes, how ?

Any help would help me so much.

Source: Windows Questions

LEAVE A COMMENT