Enforce running the script as administrator
suggest change#requires -RunAsAdministrator works on Windows PowerShell 4.0 and later, and on PowerShell 7 on Windows. It has no effect on non-Windows hosts.
#requires -RunAsAdministrator
After trying to run this script without admin privileges, you will see this error message
.\script.ps1 : The script ‘script.ps1’ cannot be run because it contains a “#requires” statement for running as Administrator. The current Windows PowerShell session is not running as Administrator. Start Windows PowerShell by using the Run as Administrator option, and then try running the script again.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents