icacls remove user variable


  1. Posts : 70,915
    64-bit Windows 11 Pro for Workstations
       #1

    icacls remove user variable


    Does anyone know how to use a variable for the user name to remove from file permissions using the icacls or some other command?

    I'm trying to get a command to use for this to have a remove "Account Unknown" context menu to make it easier to remove them.

    "Account Unknown*" doesn't work in the command for the account name.

    Add Reset Permissions to Context Menu in Windows | Windows 10 Tutorials


    icacls "<full path of file/folder>" /remove <account name> /T /C

    OR

    icacls <Drive letter>:\*.* /remove <account name> /T /C

    icacls remove user variable-account_unknown.png
      My Computers


  2. Posts : 1,471
    Win10 Home x64 - 1809
       #2

    Hey Brink,
    I'm guessing the SID won't always be the same? ... icacls "<full path of file/folder>" /remove *S-1-5-21: /T /C
    PowerShell - Script Remove orphaned SIDs from File/Folder ACL (PowerShell)
      My Computers


  3. Posts : 70,915
    64-bit Windows 11 Pro for Workstations
    Thread Starter
       #3

    It should always use the "S-1-5-21" for a local account, but probably not if anything else (ex: domain).

    It's a good start. I'll play with it.

    Thank you.
      My Computers


  4. Posts : 70,915
    64-bit Windows 11 Pro for Workstations
    Thread Starter
       #4

    Just tested, and it didn't remove it.

    icacls remove user variable-test.png
      My Computers


  5. Posts : 2,450
    Windows 10 Pro x64
       #5

    Brink said:
    Just tested, and it didn't remove it.

    icacls remove user variable-test.png

    Hi Shawn

    I tried your method, to delete an orphan (deleted) local account, which for some unexplained reason has been inserted in all my User folders, but it failed, as it did with you!
    So I made a PowerShell script, which works perfectly, at least in my end.

    Clear-SID.ps1

    Maybe you could give it a try.
    Please note that you need to open the script and fill in your own $folder and $OrphanSID variables, before you run it!
    (Or you can customize it to accept them as parameters)
      My Computer


  6. Posts : 70,915
    64-bit Windows 11 Pro for Workstations
    Thread Starter
       #6

    Thank you Dimitri.
      My Computers


  7. Posts : 2,450
    Windows 10 Pro x64
       #7

    You're very welcome.
    I would be really interested to hear your results!
      My Computer


  8. Posts : 14,051
    Windows 11 Pro X64 22H2 22621.1848
       #8

    Shawn, doesn't %username% work?
      My Computers


  9. Posts : 70,915
    64-bit Windows 11 Pro for Workstations
    Thread Starter
       #9

    Hello Rich,

    It would for the path of the user profile folder, but I was hoping for a variable that could be used for the "Account Unknown" SID so it could be applied globally without having to use a unique SID.
      My Computers


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 03:39.
Find Us




Windows 10 Forums