Answers to Activities and Exercises

Chapter 1

Activities

  1. You can use ADD_FILE_CONTEXT_MENU_RUNPOWERSHELL, like this:
    msiexec.exe /package c:\Users\WDAGUtilityAccount\Downloads\PowerShell-7.2.1-win-x64.msi /quiet REGISTER_MANIFEST=1 USE_MU=1 ENABLE_MU=1 ADD_FILE_CONTEXT_MENU_RUNPOWERSHELL=1
  2. By using kill(). Charming, right? CloseMainWindow() might work for a graphical process, and Close() will ask politely, but kill() should do it. Note that sometimes it won’t, for instance, if the process you are trying to kill is running with higher privileges than the account you are running PowerShell with.

    You can use it like this. Here’s my list of pwsh processes:

Figure A.1 – Some PowerShell processes

Let’s get rid of 4052:

Figure A.2 – Fewer ...

Get PowerShell 7 Workshop now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.