Setting up your environment
Preparing your environment for SharePoint Online scripting is very simple.
PowerShell execution policy
As the preferred scripting tool for administrators, PowerShell security is paramount. We will review the execution policy in depth in Chapter 6, Script Automation, but by default it restricts scripts to running only in an interactive session.
In this mode, you cannot execute scripts in .ps1
files (not even in the interactive mode) and unattended scripts will be blocked.
In the following example, we attempt to execute the HelloWorld.ps1
file. The call is blocked and the error message suggests that you look into the execution policy setting.
In the next line, we use the Get-ExecutionPolicy
command to get a list of settings for all the different execution scopes.
The execution policy is effective on a certain context. The default scope is CurrentUser
, this means that your policy changes will only apply to your account unless a specific scope is set. This is important...