Cmdline script to recreate AppData folder (Non-Admin)

Arvind Kumar 6 Reputation points
2022-06-30T19:10:55.327+00:00

I am looking for a simple cmdline script or set of commands in a correct sequence to recreate AppData folder along with all the symlinks and correct permissions / folder structure.

This script or set of commands should be able to run with Non-Admin priviledges

Target OS: Windows 10

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
11,195 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Limitless Technology 39,516 Reputation points
    2022-07-03T12:49:09.21+00:00

    Hi there,

    This can be accomplished with a loop. In order for the script below to work, you will need to place test.xml in the same location as the script.

    Powershell
    $Users = (Get-ChildItem C:\Users).Name

    ForEach($User in $Users) {

    New-Item -Path "C:\Users\$User\AppData\Roaming\" -Name "triage" -ItemType "directory" -ErrorAction SilentlyContinue  
    Copy-item "$PSScriptroot\test.xml" -destination "C:\Users\$user\AppData\Roaming\triage"  
    

    }

    How to make a file in localappdata location using powershell

    https://techcommunity.microsoft.com/t5/windows-powershell/how-to-make-a-file-in-localappdata-location-using-powershell/m-p/1804805

    ---------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept it as an answer--


  2. MotoX80 32,911 Reputation points
    2022-07-04T13:08:59.657+00:00

    Disclaimer: use at your own risk.

    I found 5 junctions. If you are restoring your own account's appdata this should recreate them. If not, replace %username% with the userid.

    md C:\Users\%username%\AppData\Local  
    cd C:\Users\%username%\AppData\Local  
    mklink /j "Application Data"  C:\Users\%username%\AppData\Local  
    mklink /j  History C:\Users\%username%\AppData\Local\Microsoft\Windows\History  
    mklink /j  "Temporary Internet Files" C:\Users\%username%\AppData\Local\Microsoft\Windows\INetCache  
                 
      
    md C:\Users\%username%\AppData\Local\Microsoft\Windows  
    cd C:\Users\%username%\AppData\Local\Microsoft\Windows  
    mklink /j  "Temporary Internet Files" C:\Users\%username%\AppData\Local\Microsoft\Windows\INetCache  
       
      
    md C:\Users\%username%\AppData\Local\Microsoft\Windows\INetCache  
    cd C:\Users\%username%\AppData\Local\Microsoft\Windows\INetCache  
    mklink /j  Content.IE5 C:\Users\%username%\AppData\Local\Microsoft\Windows\INetCache\IE  
                    
    

    For permissions, I happen to have a PS script that analyzes a folder structure and generates the icacls commands to reset permissions on the folders. It doesn't look at files though. I ran this on my testuser account on a Win10 21H2 VM. You would need to change all instances of "testuser" to your account name. You may want to pick and choose which ones you want to apply.

    217340-appdataperms.txt

    0 comments No comments