How do I translate the below command to Powershell:
Tasklist /FI "IMAGENAME eq Notepad.exe" | Find /i "Notepad.exe"
Thanks.
Technology Tips and News
How do I translate the below command to Powershell:
Tasklist /FI "IMAGENAME eq Notepad.exe" | Find /i "Notepad.exe"
Thanks.
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
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"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