PowerShell – Run script in new console window

Have you ever had to run powershell script in a new console window with your for example admin account?

param (
[Parameter(Mandatory=$true)]
[string]$command
)
runas /user:domain\user_name "powershell.exe -noExit -command $command"

I have that saved as “run-powershel_command.ps1

usage:
run-powershell_command.ps1 "get-aduser bob"

this will ask you for the password for the hardcodded username once that is provided it will open new window and execute the command.

Leave a Reply

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

1 × 2 =

This site uses Akismet to reduce spam. Learn how your comment data is processed.