Powershell Runas Explorer

I am new to windows pwershell. I am working on my first cmdlet. I want to open explorer as a runas for another user. I want to add to the code to automaticall add in our domain so that we just have to type our username and not domain\username. I am sure this is easy, but driving me nuts..Thanks.
#Get UserInfo
$UserInfo = Get-Credential

#Spawn instance using new account
Start-Process –cred $UserInfo explorer.exe

Open in new window

Who is Participating?
netjgrnautConnect With a Mentor Commented:
You can't edit data in the Get-Credential cmdlet in flight.  That would be a security Don't.  In the same vein, you can't edit the .UserName property of the resulting object either.

You'd have to prompt your user twice - once for the UserName, then again for the password.  In the middle, you could construct the correct Domain\UserName and pass it to the Get-Credential cmdlet for the second request.

IMO, that sounds like a lot of coding work (and an awkward user experience) just to avoid typing Domain\ before your user name.

But... if you really want to... (this is written around command line processing; dialog box driven would be different)

Set-ItemProperty 'HKLM:\SOFTWARE\Microsoft\PowerShell\1\ShellIds' ConsolePrompting $true
$adDom = "YOURDOMAIN\"

#Get "friendly" UserName
$uName = Read-Host "Enter RunAs UserID"

#Prompt for password
$UserName = $adDom + $uName
$UserCred = Get-Credential $UserName

#Spawn instance using new account
Start-Process –cred $UserCred explorer.exe

Open in new window

Hope that helps.
Your still trying to get a workaround for stopping/restarting the shell? I would be surprised if PS worked.....
"still trying..."  Did I miss a step?

I read this as an effort to launch a new file explorer window using alternate credentials.

Context would help.  :-)
Worried about phishing attacks?

90% of attacks start with a phish. It’s critical that IT admins and MSSPs have the right security in place to protect their end users from these phishing attacks. Check out our latest feature brief for tips and tricks to keep your employees off a hackers line!

tomtom98Author Commented:
It works just as he says...have to type in password twice and it brings up an instance of explorer.
Under ALTERNATE credentials? Verified by seeing this in the Task Manager?


Sorry, that wasnt towards your work, you did a fine job.  We had a similar thread a weekish or so ago, and we came to the conclusion that since IE7, this was no longer possible..... Windows 7 Just doesn't allow it anymore.... So for you to accomplish it, bravo....
Well, I ran my tests launching cmd.exe here.  I'm on a network where I have both admin and non-admin credentials.  Running the above script under my non-admin account, and entering my admin credentials, got me a cmd.exe window where "whoami" resplied with my admin account.

So there's that.   ;-)
Yea, most apps can still run side by side in different credentials, but Explorer.exe, to browse the file system/control panel etc has not been done as far as I had seen.... Only workaround I know of is to kill explorer from a RunAs'd CMD prompt, and restart it, which now loads under the Admin creds....
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.