Quantcast
Channel: Powershell – TheITBros
Viewing all articles
Browse latest Browse all 91

Managing Office 365 Using Azure Active Directory Module for Windows PowerShell

$
0
0
azure AD module for windows powershell

The Office 365 platform includes a PowerShell module that allows you to manage Office 365 organization settings, configure users and licenses from the Command prompt. As with Exchange, there are several things that you can’t simply perform from the GUI in Office 365. To connect to Office 365 from PoSh CLI, you need to install additional software.

As a workstation, only 64 bit versions of Windows 10, 8.1, Windows 7 SP1 or Windows Server 2016/2012 R2 / 2012 / 2008R2 with .NET Framework version not lower than 3.5.1 can be used.

  1. Download and installMicrosoft Online Services Sign-In Assistant (https://www.microsoft.com/en-us/download/details.aspx?id=41950)
  2. Install the module Azure Active Directory Module for Windows PowerShell from the NuGet or PowerShellGallery repository using the command:
    Find-Module -Name MSOnline | Install-Module -Force
    

    (https://www.powershellgallery.com/packages/MSOnline/1.1.183.8)
    windows azure active directory module for windows powershell

Now you can connect to your Office 365 subscription in Azure Active Directory.

Run the PowerShell console and import the module into your session:

Import-Module MSOnline

If you are using Multifactor Authentication (MFA), run the command

Connect-MsolService

In the Azure Active Directory PowerShell window that appears enter the username (use full UPN – User principal name) and the password for Office 365, and enter the confirmation code from your phone.

Note. Your account must be a member of the administrative role of Office 365.

azure active directory module for windows powershell

For usual authentication by the username and password, first save the Office 365 administrative credentials to a PoSh variable:

$o365Credential = Get-Credential

And then connect to your subscription with the command:

Connect-MsolService -Credential $o365Credential

Upon completion of the command, a connection with your Office 365 tenant will be established.

The list of accepted domains in your organization can be displayed by the command:

Get-AcceptedDomain

List the available licenses in your account:

Get-MsolAccountSku

The cmdlet returns all SKUs belonging to the organization. You will receive detailed licensing information, find out how many licenses are available and how much is used.

Now display the list of Office 365 users:

Get-MsolUser

As you can see, the list indicates whether the license is assigned to the user or not.

office 365 powershell module

You can check the user license type:

GetMsolUser –UserPrincipalName user1@theitbros.com

You can create a new user using the New-MsolUser cmdlet:

New-MsolUser -UserPrincipalName andyhornet@theitbros.onmicrosoft.com -DisplayName 'Andy Hornet' -FirstName Andy -LastName Hornet' -LicenseAssignment theitbros:ENTERPRISEPACK -UsageLocation US

If you do not specify the -Password argument when creating a user, a random password will be generated and assigned for the user.

To set a password that will never expire for Office 365 user (not recommended), you should run the following command:

Get-MSOLUser –UserPrincipalName andyhornet@theitbros.onmicrosoft.com| Set-MsolUser -PasswordNeverExpires $true

For the convenience for choosing a specific license, use this command:

$LicenseSKUid = Get-MsolAccountSku | Out-GridView -Title 'Select a license type’-OutputMode Single | Select-Object -ExpandProperty AccountSkuId

List the users who are not assigned a license:

$Users = Get-MsolUser -All -UnlicensedUsersOnly

Assign usage location for the users that was found:

$Users | Set-MsolUser -UsageLocation US

Now you can assign licenses to all selected users:

$Users | Set-MsolUserLicense -AddLicenses $LicenseSKUid

The post Managing Office 365 Using Azure Active Directory Module for Windows PowerShell appeared first on TheITBros.


Viewing all articles
Browse latest Browse all 91

Trending Articles