Office 365 PowerShell Basics Part 1

Office 365 PowerShell Basics Part 1


Knowing PowerShell is essential for any Office 365 Administrator or consultant.  There are a lot of commands as there are many services and products in Office 365.  Below I'll list a few of the basics to get you started.  This article does assume a level of basic familiarity with PowerShell.



I'm a good believer in balance and when you can do something in the GUI it's often quicker than PowerShell however there are two reasons why you have to learn PowerShell to be effective.


  1. Some commands are only available in PowerShell
  2. If you end up repeating steps in the GUI for multiple users, groups or sites for instance this can be hugely time consuming and in-practical as its prone to error.  Running a PowerShell script is essential for these actions.  Who wants to manually edit 500 users through the GUI, not me!


Logging in


$cred = Get-Credential
(Enter credentials for O365, this sets the viable for those credentials)
Import-Module MSOnline
(imports the O365 PowerShell module)
Connect-MSolService -Credential $cred

(connects using the viable of saved creds)

Dealing with passwords

Get-msoluser | Set-msoluser -strongpasswordrequired $true
(this sets strong passwords for O365 cloud identities)
Set-MsolUser -UserPrincipleName <user ID> -PasswordNeverExpires $true
EXAMPLE: Set-MsolUser -UserPrincipleName matt.fooks@cloudsinreach.com -PasswordNeverExpires $true
(Set a users password to not expire)
Get-MsolUser | Set-MsolUser -PasswordNeverExpires $true
(Set all passwords to not expire)

Creating users

New-MsolUser -UserPrincipalName “Ryu.Oshu@cloudsinreach.com” -FirstName Ryu -LastName Oshu -DisplayName Ryu Oshu
$users = Import-Csv D:\Imports.Csv
$users | ForEach-Object {New-MsolUser -UserPrincipalName $_.UserName -FirstName $_.FirstName -LastName $_LastName -DisplayName $_.DisplayName }
(Create new cloud users in bulk from importing from a CSV, the CSV just need the columns in the variable fields)

Bulk Updating of user information
$user_file = Import-CSV D:\users.csv
(Create a CSV and a variable)
$user_file | ForEach {Set-user -UserPrincipalName $_.UserName -JobTitle $_.JobTitle}
(Then using the variable update the information that is contained in the CSV)

Assigning users licenses

Get-MsolUser -UnlicensedUsersOnly
(Get the unlicensed users)
Get-MsolAccountSku
(See how many licenses we have)
Set-MsolUserLicense -UserPrincipalName “Ali@cloudsinreach.com” -AddLicenses “cloudsinreach:ENTERPRISEPACK”
Get-MsolUser -UnlicensedUsersOnly | Set-MsolUserLicense -AddLicenses “coudsinreach:ENTERRISEPACK”
(Bulk assign licenses to all unlicensed users)
I'll post part 2 next week.

Comments

Popular posts from this blog

Microsoft 365 Ask the Expert Panel in Leeds

Microsoft Threat Protection - yet another dashboard or a viable security solution?

Azure Information Protection and Information Protection?