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:

  1. Get a list of all the current processes on the system and save them to a text file called "before.txt"
  2. Launch a new browser window (Chrome, Edge, Firefox - your choice)
  3. Get a new list of all the current processes on the system and save them to a text file called "after.txt"
  4. Using the compare-object cmdlet in PowerShell, find the new process ID for the browser you just opened
  5. 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!