MSOnline PowerShell

MSOnline PowerShell module for Microsoft 365 and Azure AD management.

Module Setup & Connection

Install-Module -Name MSOnline

Install MSOnline PowerShell module

Import-Module MSOnline

Import MSOnline module

Connect-MsolService

Connect to Microsoft Online Services

Connect-MsolService -Credential $cred

Connect with stored credentials

Get-Command -Module MSOnline

List all MSOnline cmdlets

Get-Module MSOnline

Check if module is loaded

User Management

Get-MsolUser

Get all users

Get-MsolUser -UserPrincipalName user@domain.com

Get specific user

Get-MsolUser -All

Get 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 $true

Block user sign-in

Set-MsolUser -UserPrincipalName user@domain.com -BlockCredential $false

Unblock user sign-in

Remove-MsolUser -UserPrincipalName user@domain.com

Delete user (soft delete)

Remove-MsolUser -UserPrincipalName user@domain.com -RemoveFromRecycleBin

Permanently delete user

Restore-MsolUser -UserPrincipalName user@domain.com

Restore deleted user

Get-MsolUser -ReturnDeletedUsers

List deleted users

License Management

Get-MsolAccountSku

List all available licenses

Get-MsolUser -UserPrincipalName user@domain.com | Select-Object Licenses

Get 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 -UnlicensedUsersOnly

Find unlicensed users

Get-MsolUser -All | Where-Object {$_.IsLicensed -eq $true}

Find all licensed users

Set-MsolUserLicense -UserPrincipalName user@domain.com -LicenseOptions $options

Assign license with disabled services

Group Management

Get-MsolGroup

Get 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-MsolDomain

List all domains

Get-MsolDomain -DomainName domain.com

Get specific domain details

New-MsolDomain -Name newdomain.com

Add new domain

Confirm-MsolDomain -DomainName domain.com

Verify domain ownership

Set-MsolDomain -Name domain.com -IsDefault

Set default domain

Remove-MsolDomain -DomainName domain.com

Remove domain

Get-MsolDomainVerificationDns -DomainName domain.com

Get DNS verification records

Role & Admin Management

Get-MsolRole

List 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.com

Add user to admin role

Remove-MsolRoleMember -RoleName "Company Administrator" -RoleMemberEmailAddress user@domain.com

Remove user from admin role

Get-MsolUserRole -UserPrincipalName user@domain.com

Get user admin roles

Service Principal & Apps

Get-MsolServicePrincipal

List 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-MsolCompanyInformation

Get tenant company information

Set-MsolCompanySettings -UsersPermissionToCreateGroupsEnabled $false

Disable user group creation

Get-MsolCompanyInformation | Select-Object DisplayName,InitialDomain

Get company name and initial domain

Get-MsolSubscription

List all subscriptions

Get-MsolPartnerContract

List partner contracts (CSP)

Contact Management

Get-MsolContact

Get all contacts

Get-MsolContact -ObjectId <guid>

Get specific contact

Remove-MsolContact -ObjectId <guid>

Delete contact

Device Management

Get-MsolDevice

List 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.com

Get devices by owner

Reporting

Get-MsolUser -All | Measure-Object

Count total users

Get-MsolUser -All | Where-Object {$_.IsLicensed -eq $true} | Measure-Object

Count licensed users

Get-MsolUser -All | Where-Object {$_.BlockCredential -eq $true}

Find blocked users

Get-MsolAccountSku | Select-Object AccountSkuId,ActiveUnits,ConsumedUnits

License usage report

Get-MsolUser -All | Select-Object DisplayName,UserPrincipalName,IsLicensed | Export-Csv users.csv

Export user list to CSV

Federation & SSO

Get-MsolFederationProperty -DomainName domain.com

Get federation settings

Set-MsolDomainAuthentication -DomainName domain.com -Authentication Managed

Convert to managed authentication

Set-MsolDomainAuthentication -DomainName domain.com -Authentication Federated

Convert to federated authentication

Get-MsolDomainFederationSettings -DomainName domain.com

Get 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 -NoTypeInformation

Export all users to CSV

Session Connection Procedure

# Step 1: Verify module installation

Get-Module -ListAvailable MSOnline

# Step 2: Install module if missing

Install-Module -Name MSOnline -Force

# Step 3: Import module

Import-Module MSOnline

# Step 4: Connect to Microsoft Online

Connect-MsolService

# Step 5: Verify connection

Get-MsolCompanyInformation

# Alternative: Connect with credentials

$cred = Get-Credential; Connect-MsolService -Credential $cred

Session Disconnection Procedure

# Step 1: Verify active session

Get-MsolCompanyInformation

# Step 2: Close PowerShell session

MSOnline has no Disconnect cmdlet - close session

# Step 3: Remove module (optional)

Remove-Module MSOnline

# Note: For credential cleanup

Start new PowerShell session for clean state