Batch Script – Get User’s SID One-Liner

While researching a way to try and send files to a user’s Recycle Bin from a batch script, I came across this one liner either at StackExchange or SuperUser forums somewhere. FYI, there is no way natively to send something to the trash without using a VB script or some third party utility. Yes you can physically move the files into the C:\$Recycle.Bin\<UsersSID> folder, but the files will not show up in Explorer and won’t be removed when you empty the trash that way.

FOR /F "tokens=1,2 delims==" %%s IN ('wmic path win32_useraccount where name^='%USERNAME%' get sid /value ^| find /i "SID"') DO SET SID=%%t

Leave a Reply