Question: Using PowerShell ISE or VSCode, create a PowerShell script that will do the following: Get a list of all the current processes on the system
Using PowerShell ISE or VSCode, create a PowerShell script that will do the following:
- Get a list of all the current processes on the system and save them to a text file called "before.txt"
- Launch a new browser window (Chrome, Edge, Firefox - your choice)
- Get a new list of all the current processes on the system and save them to a text file called "after.txt"
- Using the compare-object cmdlet in PowerShell, find the new process ID for the browser you just opened
- Once the process ID has been identified, kill the process using that process ID
Upload the script. Paste screenshots of the results here - including a before the new browser was open screenshot, after the new browser was open screenshot, and an after the browser was "killed" screenshot
my code is below i keep getting errors and get the firefox process killled
# list processes into text file Get-Process | Select-Object -Expand Name > before.txt
#start browser
Invoke-Item "C:\program Files\Mozilla Firefox\firefox.exe"
#delay browser start by 3 seconds to run app Start-Sleep -s 3
#list processes into after.txt
Get-Process | Select-Object -Expand Name > after.txt
#compare txt files and kill the firefox browser
Compare-Object (Get-Content before.txt) (Get-Content after.txt) | select -ExpandProperty InputObject > final.txt
$list=Get-Content final.txt; Get-Process $list | kill -Force
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
