PS: O365 Commands

less than 1 minute read

Description:

The following is a list of Office 365 commands you can use with Powershell. Ironically, I chose Powershell as my scripting language of choice for everything except this, but the general public chooses to learn powershell because it’s the primary way to interact with Office 365. I have a team that does this so I get little interaction though I will be happy to update this with anything I do use! The general connection setup is like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
   Install-Module AzureAD
   Install-Module MSOnline

   Connect-MsolService

   $a = get-msoluser -UserPrincipalName "user@domain.com"
   $a | select *

   Connect-AzureAD
   Get-AzureADTenantDetail

   $d = Get-AzureADUser -ObjectId "user@domain.com"
   $d | select *
   Get-AzureADUser -ObjectId $d | Select -ExpandProperty ExtensionProperty

Although this is all supposed to be moving to MS Graph soon. Hopefully by the time I will be using this, everything will be done with a single module!

To Delete A User Permanently

1
2
3
4
   Get-MsolUser -ReturnDeletedUsers
   Remove-MsolUser -UserPrincipalName 'user@domain.com' -RemoveFromRecycleBin
   # or
   Get-MsolUser -ReturnDeletedUsers | Remove-MsolUser -RemoveFromRecycleBin -Force

To add application as global administrator

1
2
3
   Connect-MSolService
   $ClientWebApp = Get-MsolServicePrincipal -AppPrincipalId $someAppID
   Add-MsolRoleMember -RoleName "Company Administrator" -RoleMemberType ServicePrincipal -RoleMemberObjectId $ClientWebApp.objectID

Comments