Listen to this Post
This all-in-one PowerShell script installs and connects to 9 key Microsoft 365 PowerShell modules, such as Exchange Online, MS Graph, SharePoint Online, SharePoint PnP, MS Teams, Compliance Center, Azure AD, etc. The highlight is that all can be achieved by executing a single cmdlet.
GitHub Download: https://lnkd.in/gGKwsvMi
Script Highlights:
- Automatically installs required M365 PowerShell modules upon confirmation.
- Connect to one or more Office 365 services via PowerShell using a single cmdlet.
- Supports MFA-enabled accounts.
- Supports certificate-based authentication.
You Should Know:
1. Installing Required Modules
To manually install Microsoft 365 PowerShell modules, use:
Install-Module -Name ExchangeOnlineManagement Install-Module -Name Microsoft.Graph Install-Module -Name MicrosoftTeams Install-Module -Name SharePointPnPPowerShellOnline
2. Connecting to Microsoft 365 Services
For basic authentication (without MFA):
Connect-ExchangeOnline -UserPrincipalName [email protected] Connect-MgGraph -Scopes "User.Read.All" Connect-MicrosoftTeams -AccountId [email protected]
For MFA-enabled accounts:
Connect-ExchangeOnline -UserPrincipalName [email protected] -UseMultiFactorAuthentication Connect-MgGraph -Scopes "User.Read.All" -UseDeviceAuthentication
For certificate-based authentication:
Connect-ExchangeOnline -AppId <AppID> -CertificateThumbprint <Thumbprint> -Organization <TenantID> Connect-MgGraph -ClientId <AppID> -TenantId <TenantID> -CertificateThumbprint <Thumbprint>
3. Verifying Connections
Check active sessions:
Get-PSSession | Select-Object State, ComputerName Get-MgContext | Select-Object Scopes, ClientId
4. Managing Exchange Online
List all mailboxes:
Get-Mailbox
Set mailbox permissions:
Add-MailboxPermission -Identity [email protected] -User [email protected] -AccessRights FullAccess
5. Managing Azure AD via Microsoft Graph
List all users:
Get-MgUser
Get a specific userβs details:
Get-MgUser -UserId [email protected] | Select-Object DisplayName, UserPrincipalName
6. Managing SharePoint Online
Connect to SharePoint:
Connect-PnPOnline -Url https://domain.sharepoint.com -Interactive
List all SharePoint sites:
Get-PnPTenantSite
7. Managing Microsoft Teams
List all Teams:
Get-Team
Export Teams data:
Get-Team | Export-Csv -Path "TeamsList.csv" -NoTypeInformation
What Undercode Say:
PowerShell remains a dominant tool for IT administrators managing Microsoft 365. Automating connections to multiple services via a single script enhances efficiency, especially in large-scale environments. Certificate-based authentication and MFA support ensure security compliance.
For Linux admins working with hybrid environments, consider using `curl` or `az cli` for Azure integrations:
az login --service-principal -u <app-id> -p <password-or-cert> --tenant <tenant-id>
For Windows event log checks:
Get-EventLog -LogName Security -Newest 50
For network diagnostics:
ping office365.com traceroute outlook.office365.com
Expected Output:
A fully automated, secure, and efficient way to manage Microsoft 365 services via PowerShell with minimal manual intervention.
References:
Reported By: Jake Admindroid – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass β