To use Powershell commands with Office 365 on a Windows 7 desktop you will need to firstly install the Microsoft Online Services Sign–in assistant. You can download this from:
32 bit version – http://g.microsoftonline.com/0BX00en/500
64 bit version – http://g.microsoftonline.com/0BX00en/501
Once you have downloaded file run it as an administrator.
Click the option to accept the license terms and press the Install button.
Allow the files to be installed.
Click the Finish button when complete.
To check that the assistant has been installed correctly navigate to the services on the machine via Start | Control Panel | Administrative Tools | Services.
Ensure that the service Microsoft Online Services Sign-in Assistant is present and started as shown above.
When complete close the services window.
Next, you will need to install the Microsoft Online Services Module for Windows Powershell. You can download this from:
Once downloaded, double click on the file to install.
Click Next to commence the installation.
Accept the license agreements and click Next to continue.
Select a location for the installation on your local machine and press Next to continue.
Press the Install button to commence the installation.
The files will now be installed to your local machine.
Press the Finish button to complete the installation process.
You should now see a new desktop icon like shown above – Microsoft Online Services Module for Windows PowerShell.
Double click the icon to launch Powershell.
You should now see a command prompt like shown above. This is different from the normal command prompt and can be denoted by the initials PS at the beginning of each line.
It is a good idea to alter the default execution policy of PowerShell on your system via the command:
If you don’t do this you may see an error like:
In this case set the section policy as shown above and re-run the powershell command that generated the issue.
At the command prompt type the following lines followed by the ENTER key.
This will load the Microsoft Online Powershell commandlets into the environment so they can be used. It is normally already loaded when you run this, however it is good practice to ensure that it is loaded in case you ever launch just the standard Powershell environment.
You next need to capture the credential with which you wish to login to the Microsoft Online environment with. To do this enter the following command to assign the credentials to a variable $cred.
This command will pop up the credential request window you see shown above. You need to enter the login to the Office 365 environment from which you wish to run these command. This will generally be an administrator.
Use the following command to connect to the Microsoft Online Service
connect-msolservice –credential $cred
Once these command are complete you are ready to use Powershell with the Office 365 environment you have logged into.
The following command will display a list of all the users configured in the Office 365 environment and the expiry status of their password:
get-msoluser –all | format-table userprincipalname, passwordneverexpires
If you need to work with Exchange Online then you will need to run the following commands to establish a connection with those services directly:
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $Cred -Authentication Basic -AllowRedirection
Once you do this you should see a number of modules loading
With the connection to Exchange online now established you can run commands like