How do I start a new powershell instance and run commands in it?

Viewed 1861

This is what I'm trying to accomplish:

I need a user to automatically run a powershell script when he logs into the computer, have the script start an Elevated Powershell Prompt(the same as if the user could click on Run Powershell as Administrator) and then have it run some commands in the new Powershell Object, then close the new Powershell object.

This function currently will create and run a new Powershell object in Elevated mode.

function Set-Elevation
{
   # Create a new process object that starts PowerShell
   $newProcess = New-Object System.Diagnostics.ProcessStartInfo "powershell";
   # Indicate that the process should be elevated
   $newProcess.Verb = "runas";
   # Start the new process
   [System.Diagnostics.Process]::Start($newProcess) | Out-Null
}

However, how would I get it to run new commands in there? And how would I close the object afterward?

Any tips on the syntax would be appreciated.

2 Answers
Related