Do you remember the first time you had to connect to an online service like Exchange Online via PowerShell and got a vague security error and had to read pages of documentation to figure out what was going on?

I sure do, I also remember I had a bit of trouble finding exactly what I needed to do, and also making sure the code I was being told to run was safe and wasn’t going to brick my computer.

Let’s take my use case, I needed to connect to Exchange Online to set up some Dynamic Distribution Groups, which can only be done via PowerShell on my computer, and connect it to Exchange Online.
I follow the Microsoft Documentation and get ExchangeOnlineManagement installed and go to import the module, then I get the red wall of text. “Cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies”

Screenshot of a powershell error for Importing Exchange Online

Okay, so what’s wrong? By default, Execution is disabled by default and you’ll need to update the Execution Policy on your computer.

It’s a good idea to see what your current Execution Policy is in case it’s being managed by your organization with a Group Policy or something else before you break something you shouldn’t.

Get-ExecutionPolicy -List
This will show what your current Execution Policy is.

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

This does two things:
RemoteSigned: It only allows scripts created locally or signed by a trusted publisher
Scope CurrentUser: Applies this setting just for the user account logged in, leaving system-wise settings unchanged.

I personally used the RemoteSigned parameter for the Execution Policy and CurrentUser for Scope to ensure only trusted publisher and locally created scripts are ran and that only my user can run those scripts.

Powershell screenshot of Get Execution Policy and Set Execution Policy

After running that command, I was able to get connect to Exchange Online and set up those Dynamic Distribution Groups.

I hope this helped you get set up to run commands remotely with PowerShell. If you want to dive a bit deeper into Execution Policies, Microsoft obviously has a lot more info on it.