Modern authentication (PowerShell script to connect O365 Admin center, Exchange Online)

Rohit 6 Reputation points
2022-08-16T02:32:57.747+00:00

Currently using below scripts in PowerShell (unattended mode) - Can you provide and advise for below queries.

  1. As we know that, Microsoft is depreciating basic authentication in Oct2022. In both scripts, it seems bot is utilising basic authentication? Is it correct understanding
  2. If yes, it will impact both scripts during execution after Oct 2022. How to mitigate this for authentication? Do i have to make any changes in script as modules are already installed in Production servers.

Script #1 : Allocate O365 licenses (as arguments) to new user (O365 Admin center)

$cred = New-Object System.Management.Automation.PsCredential($Botusername, (ConvertTo-SecureString $Password -AsPlainText -Force))
Import-Module MSOnline
Connect-MsolService -Credential $cred
Set-MsolUser -UserPrincipalName $Name -UsageLocation AU
Set-MsolUserLicense -UserPrincipalName $Name -AddLicenses $License1, $License2
Get-msoluser -UserPrincipalName $Name | select Licenses

Scripts #2 : Add new user in DL (Exchange Online)

param([Parameter(Mandatory=$true)] $Botusername,[Parameter(Mandatory=$true)] $Password,[Parameter(Mandatory=$true)] $username,[Parameter(Mandatory=$true)] $MailGroup)
$cred = New-Object System.Management.Automation.PsCredential($Botusername, (ConvertTo-SecureString $Password -AsPlainText -Force))
Import-Module ExchangeOnlineManagement
Connect-ExchangeOnline -Credential $cred
Add-DistributionGroupMember -Identity $MailGroup -Member $username

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Rohit 6 Reputation points
    2022-08-22T06:35:57.047+00:00

    Hi @Limitless Technology : You have provided commands for Exchange Online. Do you have commands for O365 Admin center (to connect MsolService via PowerShell commands)?

    1 person found this answer helpful.

  2. Limitless Technology 39,926 Reputation points
    2022-08-16T14:45:02.797+00:00

    Hello

    Thank you for your question and reaching out. I can understand you are having query\issues related to

    I believe you can use certificate based authentication Once you have changed to Certificate Based Authentication, the above cmdlet pattern will need to be changed to use Connect-Exchange Online along with other necessary parameters. For example:

    Connect-ExchangeOnline -CertificateFilePath "C:\temp\automation-cert.pfx" -CertificatePassword (ConvertTo-SecureString -String "<My Password>" -AsPlainText -Force) -AppID "36ee4c6c-0812-40a2-b820-b22ebd02bce3" -Organization "contoso.onmicrosoft.com"

    Reference :

    https://techcommunity.microsoft.com/t5/exchange-team-blog/modern-auth-and-unattended-scripts-in-exchange-online-powershell/ba-p/1497387

    ---------------------------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept as answer--

    0 comments No comments

  3. Rohit 6 Reputation points
    2022-08-17T23:58:41.397+00:00

    @Limitless Technology - Thanks for sharing solution (I can securely put this file and use it in script). One thing to check - what this automation-cert.pfx file contains?

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.