Impersonate Another User in Windows

I have a folder full of obsolete roaming profile folders that I really want to tidy up. Due to the very restrict folder permissions on these folders, I found it would be a lot faster and easier if I can impersonate an individual user on the server and perform the archive job using RoboCopy command line.

The built-in “RunAs” seems to be a perfect command line made for the job. Typically, you can execute the command like:

runas /user:username@domainame "command and argument"

Moreover, it performs even quick with switch /noprofile that tells the command line to not load the user’s profile.

So, I could use the following command line if I would like to move a roaming profile folder from one server to another server.

runas /noprofile /user:username@domainname "robocopy \\server1\profiles\user1 \\server2\profiles\user1 /s /move"

If you prefer to open a command prompt window so you can interactive with the server, use “cmd” as the command.

runas /noprofile /user:username@domainname "cmd"

Type in the password for that user, a new command prompt window opens up with “cmd (running as so-on-so)” on the title line.

Open a new command prompt window as another user

If you would like to open a PowerShell window, use “powershell” as the command instead.

runas /noprofile /user:username@domainname "powershell"
Open a new PowerShell console as another user

Leave a Reply

Your email address will not be published. Required fields are marked *