If you are frequently administering an Microsoft Office 365 subscription through PowerShell you might find this little PowerShell script (.ps1) handy.
To administer Office 365 with PowerShell, including the Microsoft Exchange Online features, you require two things in your local PowerShell session:
- The “Microsoft Online Services Module” for Windows PowerShell. This module is downloaded and installed locally on-premise, and gives your local PowerShell session the ability to run Microsoft Online Service (“Msol”) cmdlet’s that can be used for basic Microsoft Online administration.
- A remote PowerShell session to your Microsoft Exchange Online tenant. This gives your local PowerShell session access to the Exchange Online cmdlet’s.
Note: there are currently no specific Lync Online PowerShell cmdlet’s. Any Lync Online PowerShell Administration needs to be done through the Microsoft Office 365 Customer Portal, but you can do basic user management (get/set user properties, manage user licenses etc…) through the Msol PowerShell cmdlets.
The small PowerShell script below imports the Msol Module and provides a remote PowerShell session to the Exchange Online tenant – giving you access to everything in the same local PowerShell session.
To customize the script for your Office 365 subscription, just change the $user variable to use whatever Administrative credentials you use to connect to your Office 365 subscription.
# Specify your administrative user credentials on the line below
$user = “YourAdminUserId@YourDomain.OnMicrosoft.com”
# This will pop-up a dialog and request your password
$cred = Get-Credential -Credential $user
#——– Import the Local Microsoft Online PowerShell Module Cmdlets and Connect to O365 Online ———–
Import-Module MSOnline
Connect-MsolService -Credential $cred
#———— Establish an Remote PowerShell Session to Exchange Online ———————
$msoExchangeURL = “https://ps.outlook.com/powershell/”
$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $msoExchangeURL -Credential $cred -Authentication Basic -AllowRedirection
Import-PSSession $session
#——————————————————————————————–
# You can now use the:
# 1] MSOL Powershell cmdlets such as Get-MsolUser
# 2] Exchange Online cmdlets such as Get-Mailbox
# ** It is good to remove your Remote Exchange Online session when you are all done.
# Remove-PsSession $session
Cut-and-paste this script and save it to a .ps1 file. This is particularly useful in the Windows PowerShell ISE – just load this .ps1 from the PowerShell ISE, run it, and instantly your have a local PowerShell session at your fingertips for administering the basics of Office 365 and the Exchange functionality. You can also just load a local regular PowerShell command line interface.
I include a current listing of all the Msol Module and Exchange Online PowerShell cmdlet’s.
Reference 1: Current Listing of the “Microsoft Online PowerShell Module” (Msol) CmdLets
Good reference: Windows PowerShell cmdlets for Office 365
PS H:\> Get-Command -Module MSOnline | ft Name, Definition
Name Definition
---- ----------
Add-MsolGroupMember Add-MsolGroupMember -GroupObjectId <Guid> [-GroupMemberType <Grou...
Add-MsolRoleMember Add-MsolRoleMember -RoleObjectId <Guid> [-RoleMemberType <RoleMem...
Confirm-MsolDomain Confirm-MsolDomain -DomainName <String> [-SigningCertificate <Str...
Connect-MsolService Connect-MsolService [-Verbose] [-Debug] [-ErrorAction <ActionPref...
Convert-MsolDomainToFederated Convert-MsolDomainToFederated [-SupportMultipleDomain] -DomainNam...
Convert-MsolDomainToStandard Convert-MsolDomainToStandard -PasswordFile <String> -SkipUserConv...
Convert-MsolFederatedUser Convert-MsolFederatedUser -UserPrincipalName <String> [-NewPasswo...
Get-MsolAccountSku Get-MsolAccountSku [-TenantId <Nullable`1>] [-Verbose] [-Debug] [...
Get-MsolCompanyInformation Get-MsolCompanyInformation [-TenantId <Nullable`1>] [-Verbose] [-...
Get-MsolContact Get-MsolContact [-HasErrorsOnly <Nullable`1>] [-SearchString <Str...
Get-MsolDomain Get-MsolDomain [-Status <Nullable`1>] [-Authentication <Nullable`...
Get-MsolDomainFederationSettings Get-MsolDomainFederationSettings -DomainName <String> [-TenantId ...
Get-MsolDomainVerificationDns Get-MsolDomainVerificationDns -DomainName <String> [-Mode <Nullab...
Get-MsolFederationProperty Get-MsolFederationProperty [-SupportMultipleDomain] -DomainName <...
Get-MsolGroup Get-MsolGroup [-UserObjectId <Nullable`1>] [-IsAgentRole] [-UserP...
Get-MsolGroupMember Get-MsolGroupMember [-GroupObjectId <Guid>] [-SearchString <Strin...
Get-MsolPartnerContract Get-MsolPartnerContract [-DomainName <String>] [-TenantId <Nullab...
Get-MsolPartnerInformation Get-MsolPartnerInformation [-TenantId <Nullable`1>] [-Verbose] [-...
Get-MsolRole Get-MsolRole [-TenantId <Nullable`1>] [-Verbose] [-Debug] [-Error...
Get-MsolRoleMember Get-MsolRoleMember [-RoleObjectId <Guid>] [-SearchString <String>...
Get-MsolSubscription Get-MsolSubscription [-TenantId <Nullable`1>] [-Verbose] [-Debug]...
Get-MsolUser Get-MsolUser [-City <String>] [-Country <String>] [-Department <S...
Get-MsolUserRole Get-MsolUserRole -ObjectId <Guid> [-TenantId <Nullable`1>] [-Verb...
New-MsolDomain New-MsolDomain [-Name <String>] [-Authentication <Nullable`1>] [-...
New-MsolFederatedDomain New-MsolFederatedDomain [-SupportMultipleDomain] -DomainName <Str...
New-MsolGroup New-MsolGroup [-DisplayName <String>] [-Description <String>] [-M...
New-MsolLicenseOptions New-MsolLicenseOptions -AccountSkuId <String> [-DisabledPlans <Li...
New-MsolUser New-MsolUser [-ImmutableId <String>] [-UserPrincipalName <String>...
Remove-MsolContact Remove-MsolContact -ObjectId <Guid> [-Force] [-TenantId <Nullable...
Remove-MsolDomain Remove-MsolDomain -DomainName <String> [-Force] [-TenantId <Nulla...
Remove-MsolFederatedDomain Remove-MsolFederatedDomain [-SupportMultipleDomain] -DomainName <...
Remove-MsolGroup Remove-MsolGroup -ObjectId <Guid> [-Force] [-TenantId <Nullable`1...
Remove-MsolGroupMember Remove-MsolGroupMember -GroupObjectId <Guid> [-GroupMemberType <G...
Remove-MsolRoleMember Remove-MsolRoleMember -RoleObjectId <Guid> [-RoleMemberType <Role...
Remove-MsolUser Remove-MsolUser -ObjectId <Guid> [-Force] [-TenantId <Nullable`1>...
Set-MsolADFSContext Set-MsolADFSContext [-ADFSUserCredentials <PSCredential>] -Comput...
Set-MsolCompanyContactInformation Set-MsolCompanyContactInformation [-TechnicalNotificationEmails <...
Set-MsolCompanySettings Set-MsolCompanySettings [-SelfServePasswordResetEnabled <Nullable...
Set-MsolDirSyncEnabled Set-MsolDirSyncEnabled -EnableDirSync [-TenantId <Nullable`1>] [-...
Set-MsolDomain Set-MsolDomain [-Name <String>] [-IsDefault] [-TenantId <Nullable...
Set-MsolDomainAuthentication Set-MsolDomainAuthentication -DomainName <String> -Authentication...
Set-MsolDomainFederationSettings Set-MsolDomainFederationSettings -DomainName <String> [-SigningCe...
Set-MsolGroup Set-MsolGroup [-ObjectId <Nullable`1>] [-DisplayName <String>] [-...
Set-MsolPartnerInformation Set-MsolPartnerInformation [-ObjectId <Nullable`1>] [-CompanyType...
Set-MsolUser Set-MsolUser [-ImmutableId <String>] [-ObjectId <Nullable`1>] [-U...
Set-MsolUserLicense Set-MsolUserLicense -ObjectId <Guid> [-LicenseOptions <LicenseOpt...
Set-MsolUserPassword Set-MsolUserPassword -ObjectId <Guid> [-NewPassword <String>] [-F...
Set-MsolUserPrincipalName Set-MsolUserPrincipalName -ObjectId <Guid> -NewUserPrincipalName ...
Update-MsolFederatedDomain Update-MsolFederatedDomain [-SupportMultipleDomain] -DomainName <...
Reference 1: Current Listing of the “Microsoft Online PowerShell Module” (Msol) CmdLets
Here is a good Technet Reference to Available PowerShell Cmdlets in Exchange Online:
> http://technet.microsoft.com/en-us/exchangelabshelp/dd575549
PS H:\> Get-Command –Module <exchange online module name; use Get-Module>
Name : Add-AvailabilityAddressSpace
Name : Add-DistributionGroupMember Name : Add-MailboxFolderPermission Name : Add-MailboxPermission Name : Add-RecipientPermission Name : Add-RoleGroupMember Name : Clear-ActiveSyncDevice Name : Clear-TextMessagingAccount Name : Compare-TextMessagingVerificationCode Name : Complete-Migration Name : Disable-InboxRule Name : Disable-JournalRule Name : Disable-Mailbox Name : Enable-InboxRule Name : Enable-JournalRule Name : Enable-Mailbox Name : Enable-OrganizationCustomization Name : Export-MigrationReport Name : Get-AcceptedDomain Name : Get-ActiveSyncDevice Name : Get-ActiveSyncDeviceAccessRule Name : Get-ActiveSyncDeviceClass Name : Get-ActiveSyncDeviceStatistics Name : Get-ActiveSyncMailboxPolicy Name : Get-ActiveSyncOrganizationSettings Name : Get-AdminAuditLogConfig Name : Get-AvailabilityAddressSpace Name : Get-AvailabilityConfig Name : Get-CalendarNotification Name : Get-CalendarProcessing Name : Get-CASMailbox Name : Get-CASMailboxPlan Name : Get-Contact Name : Get-DistributionGroup Name : Get-DistributionGroupMember Name : Get-DynamicDistributionGroup Name : Get-FailedContentIndexDocuments Name : Get-FederatedOrganizationIdentifier Name : Get-FederationInformation Name : Get-FederationTrust Name : Get-Group Name : Get-HotmailSubscription Name : Get-ImapSubscription Name : Get-InboxRule Name : Get-IRMConfiguration Name : Get-JournalRule Name : Get-LinkedUser Name : Get-LogonStatistics Name : Get-Mailbox Name : Get-MailboxAuditBypassAssociation Name : Get-MailboxAutoReplyConfiguration Name : Get-MailboxCalendarConfiguration Name : Get-MailboxCalendarFolder Name : Get-MailboxFolder Name : Get-MailboxFolderPermission Name : Get-MailboxFolderStatistics Name : Get-MailboxJunkEmailConfiguration Name : Get-MailboxMessageConfiguration Name : Get-MailboxPermission Name : Get-MailboxPlan Name : Get-MailboxRegionalConfiguration Name : Get-MailboxSpellingConfiguration Name : Get-MailboxStatistics Name : Get-MailContact Name : Get-MailUser Name : Get-ManagementRole Name : Get-ManagementRoleAssignment Name : Get-ManagementRoleEntry Name : Get-ManagementScope Name : Get-MessageCategory Name : Get-MessageClassification Name : Get-MessageTrackingReport Name : Get-MigrationBatch Name : Get-MigrationStatus Name : Get-MigrationUser Name : Get-MoveRequest Name : Get-MoveRequestStatistics Name : Get-OrganizationalUnit Name : Get-OrganizationRelationship Name : Get-OwaMailboxPolicy Name : Get-PerimeterConfig Name : Get-PopSubscription Name : Get-ProvisioningRequest Name : Get-Recipient Name : Get-RecipientPermission Name : Get-RecipientStatisticsReport Name : Get-RemoteDomain Name : Get-RemovedMailbox Name : Get-RetentionPolicy Name : Get-RetentionPolicyTag Name : Get-RMSTemplate Name : Get-RMSTrustedPublishingDomain Name : Get-RoleAssignmentPolicy Name : Get-RoleGroup Name : Get-RoleGroupMember Name : Get-SecurityPrincipal Name : Get-SendAddress Name : Get-ServiceStatus Name : Get-SharingPolicy Name : Get-Subscription Name : Get-SyncConfig Name : Get-TextMessagingAccount Name : Get-ThrottlingPolicy Name : Get-ThrottlingPolicyAssociation Name : Get-ToolInformation Name : Get-TransportConfig Name : Get-User Name : Import-ContactList Name : New-ActiveSyncDeviceAccessRule Name : New-ActiveSyncMailboxPolicy Name : New-AdminAuditLogSearch Name : New-AvailabilityConfig Name : New-DistributionGroup Name : New-DynamicDistributionGroup Name : New-HotmailSubscription |
Name : New-ImapSubscription
Name : New-InboxRule Name : New-JournalRule Name : New-Mailbox Name : New-MailboxAuditLogSearch Name : New-MailboxFolder Name : New-MailContact Name : New-MailMessage Name : New-MailUser Name : New-MessageClassification Name : New-MigrationBatch Name : New-MoveRequest Name : New-OrganizationRelationship Name : New-OwaMailboxPolicy Name : New-PopSubscription Name : New-ProvisioningRequest Name : New-RemoteDomain Name : New-RetentionPolicy Name : New-RetentionPolicyTag Name : New-SharingPolicy Name : New-Subscription Name : Remove-ActiveSyncDevice Name : Remove-ActiveSyncDeviceAccessRule Name : Remove-ActiveSyncMailboxPolicy Name : Remove-AvailabilityAddressSpace Name : Remove-AvailabilityConfig Name : Remove-DistributionGroup Name : Remove-DistributionGroupMember Name : Remove-DynamicDistributionGroup Name : Remove-InboxRule Name : Remove-JournalRule Name : Remove-Mailbox Name : Remove-MailboxFolderPermission Name : Remove-MailboxPermission Name : Remove-MailContact Name : Remove-MailUser Name : Remove-MessageClassification Name : Remove-MoveRequest Name : Remove-OrganizationRelationship Name : Remove-OwaMailboxPolicy Name : Remove-ProvisioningRequest Name : Remove-RecipientPermission Name : Remove-RemoteDomain Name : Remove-RetentionPolicy Name : Remove-RetentionPolicyTag Name : Remove-RoleGroupMember Name : Remove-SharingPolicy Name : Remove-Subscription Name : Resume-MoveRequest Name : Search-AdminAuditLog Name : Search-Mailbox Name : Search-MailboxAuditLog Name : Search-MessageTrackingReport Name : Send-TextMessagingVerificationCode Name : Set-AcceptedDomain Name : Set-ActiveSyncDeviceAccessRule Name : Set-ActiveSyncMailboxPolicy Name : Set-ActiveSyncOrganizationSettings Name : Set-AvailabilityConfig Name : Set-CalendarNotification Name : Set-CalendarProcessing Name : Set-CASMailbox Name : Set-Contact Name : Set-DistributionGroup Name : Set-DynamicDistributionGroup Name : Set-FederatedOrganizationIdentifier Name : Set-Group Name : Set-HotmailSubscription Name : Set-ImapSubscription Name : Set-InboxRule Name : Set-JournalRule Name : Set-LinkedUser Name : Set-Mailbox Name : Set-MailboxAuditBypassAssociation Name : Set-MailboxAutoReplyConfiguration Name : Set-MailboxCalendarConfiguration Name : Set-MailboxCalendarFolder Name : Set-MailboxFolderPermission Name : Set-MailboxJunkEmailConfiguration Name : Set-MailboxMessageConfiguration Name : Set-MailboxPlan Name : Set-MailboxRegionalConfiguration Name : Set-MailboxSpellingConfiguration Name : Set-MailContact Name : Set-MailUser Name : Set-MessageClassification Name : Set-MoveRequest Name : Set-OrganizationConfig Name : Set-OrganizationRelationship Name : Set-OwaMailboxPolicy Name : Set-PerimeterConfig Name : Set-PopSubscription Name : Set-RemoteDomain Name : Set-RetentionPolicy Name : Set-RetentionPolicyTag Name : Set-RoleGroup Name : Set-SharingPolicy Name : Set-TextMessagingAccount Name : Set-TransportConfig Name : Set-UMMailbox Name : Set-UMMailboxPIN Name : Set-User Name : Start-ManagedFolderAssistant Name : Start-MigrationBatch Name : Start-ProvisioningRequest Name : Start-RetentionAutoTagLearning Name : Stop-MigrationBatch Name : Suspend-MoveRequest Name : Test-MAPIConnectivity Name : Test-MigrationServerAvailability Name : Test-OrganizationRelationship Name : Update-DistributionGroupMember Name : Update-RoleGroupMember Name : Write-AdminAuditLog |
BRILLIANT!!!! Thanks a ton1!!!
[…] Ok interesting, will dig some more. Also have you seen this script Handy PowerShell Administration Script for Office 365 | Inside Lync might be handy for you if you are doing lots of admin via powershell. […]
[…] follow this link http://blog.insidelync.com/2011/09/handy-powershell-administration-script-for-office-365-2/ […]