Translate this command to Powershell

How do I translate the below command to Powershell:

Tasklist /FI "IMAGENAME eq Notepad.exe" | Find /i "Notepad.exe"

Thanks.

January 9th, 2014 12:25am

The best I can tell is that you are attempting to find the notepad.exe process. In PowerShell you can do any of the following. These commands are all the same, but have been included to show the difference between using the alias of Get-Process (gps) and the fact that the -Name parameter usage is optional.

Get-Process -Name notepad
Get-Process notepad
gps -Name notepad
gps notepad

If notepad is running it will return the default properties that include the ProcessName, PID (as Id), and other properties. If the process is not running it will return an error. While I wouldn't typically use the -ErrorAction parameter it might be helpful in this situation.

Get-Process -Name notepad -ErrorAction SilentlyContinue
Free Windows Admin Tool Kit Click here and download it now
January 9th, 2014 1:22am

Below is my current cmd file that I want to bring it powershell. That is IF there is a notepad process, then kill it first, then restart notepad.

Tasklist /FI "IMAGENAME eq Notepad.exe" | Find /i  "Notepad.exe"
IF  ERRORLEVEL 0 Taskkill /f /im Notepad.exe    
Sleep 3
Start "" "notepad.exe"

January 10th, 2014 11:42pm

Is this is what you are looking for?

$g=Get-Process -Name notepad -ErrorAction silentlycontinue
if($?)
{
Stop-Process -processname notepad -Force
sleep 3
Start-Process -NoNewWindow notepad.exe
}
else
{
Start-Process -NoNewWindow notepad.exe
}

--Prashanth

Free Windows Admin Tool Kit Click here and download it now
January 10th, 2014 11:57pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics