In this post we will get started with PowerShell for Office 365, before digging into more complex details related to the administration fo SharePoint, Exchange Online, Office365 Users…etc, let’s first start by getting some basic knowledges about PowerShell.
For windows users, most of the Windows editions > Windows 7 SP1, will have PowerShell installed by default, if not, you can enable it by following this simple article from Microsoft
My preferred Device and OS ? (Sorry MS, I tried all the surface devices, but can’t separate from my Mac ?)
brew cask install powershell
This assuming you have brew installed on your MacOS, if not, here is how you can install it : https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-macos?view=powershell-7#about-brew
pwsh
brew update brew cask upgrade powershell
Be re-assured, you are not expected and might not be able to remember all the commands, properties, members …etc available in PowerShell (if you do, you need to get a life ?).
However, you can easily get help from PowerShell, using some of the existant commands such as :
Get-Command *Host
Get-Help Get-SPDrive
Which will return the following output
Get-Help Get-SPDrive -Online
Get-Service | Get-Member
If the help you get from Get-Help is not up to date, or the Get-Help can’t find a specific command (this is very frequent when you install a new module), you can simply update the help section which will download all the files and details of the available commands, simply type:
Update-Help
I will skip the part where we talk about how to Write-Host, do a loop, declare a variable …etc, as this is just a quick introduction before we jump into the more serious things related to Office365.
I believe there are plenty of ressources online if you want to improve your PowerShell skills, but for me, I will just give you what we need to jump to the next step which is way more fun ?.
You can easily create a function and call from different places in your code.
Please be aware that similarly to JavaScript the function needs to be declared before you call it.
function Add ($a, $b) { $result = $a+$b Write-Host "The result is $result" }
You can simply do:
add 3,4
Let’s say you have your library of functions (Send Email, Write to Windows Log, Encrypt …etc.) you can reference your functions.PS1 file from another .PS1 script and call the functions listed in that file. For this, just type in your Main.ps1
. ./functions.ps1
In the next post, I will take you through the modules you need to install to be able to authenticate and connect to your Office365 tenant and be able to administer it properly.