I am sharing with you some quick commands on using Office 365 Power Shell to perform Office 365 admin center tasks from the command line to your Office 365 organization:

How you can Connect to Office 365:

Import Office 365 Module  : Import-Module MSOnline
Connect to your Directory  : Connect-MsolService
Users Commands:

List all users:                        get-msoluser -all
List all users with count:        get-msoluser -all | measure

Change UPN on all unlicensed users:      Get-MsolUser -all | Where { -Not $_.UserPrincipalName.ToLower().StartsWith(“admin@”) } | ForEach { Set-MsolUserPrincipalName -ObjectId $_.ObjectId -NewUserPrincipalName ($_.UserPrincipalName.Split(“@”)[0] + “@acig.com.sa”) }
Remove all unlicensed users:       Get-MsolUser -all | Where-Object {$_.isLicensed -ne "true"} | Remove-MsolUser -Force


Office 365 Licensing Information:

You can use a Power Shell script to check if users have a license assigned directly or inherited from a group:

      1. Run the connect-msolservice cmdlet to authenticate and connect to your tenant as explained on the above commands.
      2. Get-MsolAccountSku can be used to discover all provisioned product licenses in the tenant.

Thanks and hope this might helps.

      
      

2

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month