MSOnline PowerShell
MSOnline PowerShell module for Microsoft 365 and Azure AD management.
Module Setup & Connection
Install-Module -Name MSOnlineInstall MSOnline PowerShell module
Import-Module MSOnlineImport MSOnline module
Connect-MsolServiceConnect to Microsoft Online Services
Connect-MsolService -Credential $credConnect with stored credentials
Get-Command -Module MSOnlineList all MSOnline cmdlets
Get-Module MSOnlineCheck if module is loaded
User Management
Get-MsolUserGet all users
Get-MsolUser -UserPrincipalName user@domain.comGet specific user
Get-MsolUser -AllGet all users including deleted
New-MsolUser -UserPrincipalName user@domain.com -DisplayName "John Doe"Create new user
Set-MsolUser -UserPrincipalName user@domain.com -DisplayName "New Name"Update user properties
Set-MsolUserPassword -UserPrincipalName user@domain.com -NewPassword "Password123"Reset user password
Set-MsolUser -UserPrincipalName user@domain.com -BlockCredential $trueBlock user sign-in
Set-MsolUser -UserPrincipalName user@domain.com -BlockCredential $falseUnblock user sign-in
Remove-MsolUser -UserPrincipalName user@domain.comDelete user (soft delete)
Remove-MsolUser -UserPrincipalName user@domain.com -RemoveFromRecycleBinPermanently delete user
Restore-MsolUser -UserPrincipalName user@domain.comRestore deleted user
Get-MsolUser -ReturnDeletedUsersList deleted users
License Management
Get-MsolAccountSkuList all available licenses
Get-MsolUser -UserPrincipalName user@domain.com | Select-Object LicensesGet user licenses
Set-MsolUserLicense -UserPrincipalName user@domain.com -AddLicenses "tenant:ENTERPRISEPACK"Assign license to user
Set-MsolUserLicense -UserPrincipalName user@domain.com -RemoveLicenses "tenant:ENTERPRISEPACK"Remove license from user
Get-MsolUser -All -UnlicensedUsersOnlyFind unlicensed users
Get-MsolUser -All | Where-Object {$_.IsLicensed -eq $true}Find all licensed users
Set-MsolUserLicense -UserPrincipalName user@domain.com -LicenseOptions $optionsAssign license with disabled services
Group Management
Get-MsolGroupGet all groups
Get-MsolGroup -ObjectId <guid>Get specific group by ID
New-MsolGroup -DisplayName "Group Name" -Description "Description"Create new group
Set-MsolGroup -ObjectId <guid> -DisplayName "New Name"Update group properties
Remove-MsolGroup -ObjectId <guid>Delete group
Get-MsolGroupMember -GroupObjectId <guid>Get group members
Add-MsolGroupMember -GroupObjectId <guid> -GroupMemberObjectId <user_guid>Add user to group
Remove-MsolGroupMember -GroupObjectId <guid> -GroupMemberObjectId <user_guid>Remove user from group
Domain Management
Get-MsolDomainList all domains
Get-MsolDomain -DomainName domain.comGet specific domain details
New-MsolDomain -Name newdomain.comAdd new domain
Confirm-MsolDomain -DomainName domain.comVerify domain ownership
Set-MsolDomain -Name domain.com -IsDefaultSet default domain
Remove-MsolDomain -DomainName domain.comRemove domain
Get-MsolDomainVerificationDns -DomainName domain.comGet DNS verification records
Role & Admin Management
Get-MsolRoleList all admin roles
Get-MsolRole -RoleName "Company Administrator"Get specific role
Get-MsolRoleMember -RoleObjectId <guid>Get role members
Add-MsolRoleMember -RoleName "Company Administrator" -RoleMemberEmailAddress user@domain.comAdd user to admin role
Remove-MsolRoleMember -RoleName "Company Administrator" -RoleMemberEmailAddress user@domain.comRemove user from admin role
Get-MsolUserRole -UserPrincipalName user@domain.comGet user admin roles
Service Principal & Apps
Get-MsolServicePrincipalList all service principals
Get-MsolServicePrincipal -AppPrincipalId <guid>Get specific service principal
Remove-MsolServicePrincipal -AppPrincipalId <guid>Remove service principal
Get-MsolServicePrincipalCredential -AppPrincipalId <guid>Get service principal credentials
New-MsolServicePrincipalCredential -AppPrincipalId <guid>Create new credential for service principal
Company Information
Get-MsolCompanyInformationGet tenant company information
Set-MsolCompanySettings -UsersPermissionToCreateGroupsEnabled $falseDisable user group creation
Get-MsolCompanyInformation | Select-Object DisplayName,InitialDomainGet company name and initial domain
Get-MsolSubscriptionList all subscriptions
Get-MsolPartnerContractList partner contracts (CSP)
Contact Management
Get-MsolContactGet all contacts
Get-MsolContact -ObjectId <guid>Get specific contact
Remove-MsolContact -ObjectId <guid>Delete contact
Device Management
Get-MsolDeviceList all devices
Get-MsolDevice -DeviceId <guid>Get specific device
Remove-MsolDevice -DeviceId <guid>Remove device
Enable-MsolDevice -DeviceId <guid>Enable device
Disable-MsolDevice -DeviceId <guid>Disable device
Get-MsolDevice -RegisteredOwnerUpn user@domain.comGet devices by owner
Reporting
Get-MsolUser -All | Measure-ObjectCount total users
Get-MsolUser -All | Where-Object {$_.IsLicensed -eq $true} | Measure-ObjectCount licensed users
Get-MsolUser -All | Where-Object {$_.BlockCredential -eq $true}Find blocked users
Get-MsolAccountSku | Select-Object AccountSkuId,ActiveUnits,ConsumedUnitsLicense usage report
Get-MsolUser -All | Select-Object DisplayName,UserPrincipalName,IsLicensed | Export-Csv users.csvExport user list to CSV
Federation & SSO
Get-MsolFederationProperty -DomainName domain.comGet federation settings
Set-MsolDomainAuthentication -DomainName domain.com -Authentication ManagedConvert to managed authentication
Set-MsolDomainAuthentication -DomainName domain.com -Authentication FederatedConvert to federated authentication
Get-MsolDomainFederationSettings -DomainName domain.comGet domain federation settings
Bulk Operations
Import-Csv users.csv | ForEach-Object {New-MsolUser -UserPrincipalName $_.UPN -DisplayName $_.Name}Bulk create users from CSV
Get-MsolUser -All | Set-MsolUser -UsageLocation "US"Bulk set usage location
Import-Csv licenses.csv | ForEach-Object {Set-MsolUserLicense -UserPrincipalName $_.UPN -AddLicenses $_.License}Bulk assign licenses
Get-MsolUser -All | Export-Csv all-users.csv -NoTypeInformationExport all users to CSV
Session Connection Procedure
# Step 1: Verify module installationGet-Module -ListAvailable MSOnline
# Step 2: Install module if missingInstall-Module -Name MSOnline -Force
# Step 3: Import moduleImport-Module MSOnline
# Step 4: Connect to Microsoft OnlineConnect-MsolService
# Step 5: Verify connectionGet-MsolCompanyInformation
# Alternative: Connect with credentials$cred = Get-Credential; Connect-MsolService -Credential $cred
Session Disconnection Procedure
# Step 1: Verify active sessionGet-MsolCompanyInformation
# Step 2: Close PowerShell sessionMSOnline has no Disconnect cmdlet - close session
# Step 3: Remove module (optional)Remove-Module MSOnline
# Note: For credential cleanupStart new PowerShell session for clean state