April 27, 2024

SamTech 365

PowerPlatform, Power Apps, Power Automate, PVA, SharePoint, C#, .Net, SQL, Azure News, Tips ….etc

PowerShell (Part 3) – Setting up your environment for Office365

In order to start using PowerShell for Office365 Admin tasks, you need to following :

Or you can also install the module directly from PowerShell as follow:

Install-Module MSOnline
  • You need to have Office365 Administrator Rights.
  • A 64-bit machine
  • At least Windows 7 SP1+ or Windows Server 2008R2+

 

Once you have installed the pre-requisites, you need to

1- Import the module into PowerShell

For this, simply type:

Import-Module MSOnline

2- Get Connection Credentials

In order to create a credential object, we can do:

$cred= Get-Credential

Once you run this command, you will be prompted to enter your username and password. Please be aware that at this stage there is no validation of the username and password.

3- Establish Connection

Now, to connect to your tenant, just type:

Connect-MsolService -Credential $cred

Note that we pass the $cred object which contains the username and password supplied in the previous step.

If the connection is successful, you won’t see any output.

4- List all users in your tenant

In order to test that we are properly connected to our tenant, we can simply list all the users by doing :

Get-MsolUser

Which will output a table of PrincipalName, DisplayName and isLicensed boolean.