Tuesday, March 27, 2012

start or create a process in powershell

These are three possibilities to start a process in Powershell. The goal in this particular example is to open a text file called test.txt under “C:\temp” with notepad.

First solution -  cmdlet:

start-process -FilePath "$($env:SystemRoot)\notepad.exe" -ArgumentList 'C:\temp\test.txt'

Second solution – dot net:

[System.Diagnostics.Process]::Start("$($env:SystemRoot)\notepad.exe",'C:\temp\test.txt')

Third solution - wmi:

$process = [wmiclass]'Win32_Process'
$process.Create("$($env:SystemRoot)\notepad.exe C:\temp\test.txt")