
PowerShell: Checking whether you have admin rights
If you create a PowerShell script that should perform actions that require administrator rights, you can also check this in code. This allows you to make sure that your script can be executed successfully. The easiest way is with a Requires statement. 🎬 I also created a video on this topic. Requiring admin rights with a Requires statement 1 #Requires -RunAsAdministrator This line can be inserted at any point in the PowerShell code. I would always place it fairly near the top of the script so it is easy to see. But the position technically does not matter. So if the #Requires statement is in the code, it is evaluated before the rest of the code is executed. Depending on whether administrator rights are present or not, an error is returned. ...