Forum Discussion
AntJH8
Jun 09, 2021Copper Contributor
Running a script keeps stopping every couple of minutes to create a new remote powershell session
Hi, I'm trying to run a script that uses Set-Mailbox and Set-MsolUser. Every 2 minutes or so I get the following and then script carries on: Creating a new Remote PowerShell session using MFA...
VasilMichev
Jun 09, 2021MVP
That's the reality of ExO remote PowerShell, especially if you don't handle throttling. Read here for some guidance/samples on how to do it "properly": https://techcommunity.microsoft.com/t5/exchange-team-blog/running-powershell-cmdlets-for-large-numbers-of-users-in-office/ba-p/604280
AntJH8
Jun 10, 2021Copper Contributor
Hi Vasil,
I had a look at that article. I'm not running anything crazy, it's all updates on individual mailboxes. Yes we do have 12,000+ mailboxes. But this script was only processing a few accounts., see below:
$users = Import-CSV "C:\mydir\list.csv"
Foreach ($user in $users){
$user.UserPrincipalName
#Convert mailbox to shared and hide from the address list
Set-Mailbox -identity $user.UserPrincipalName -Type shared -HiddenFromAddressListsEnabled $true
Start-Sleep -milliseconds 500
#Get the list of licences
$licenses = Get-MsolUser -UserPrincipalName $user.UserPrincipalName | select -ExpandProperty licenses
Start-Sleep -milliseconds 500
#Block sign-in to the account
Set-MsolUser -UserPrincipalname $user.UserPrincipalName -UsageLocation IE -BlockCredential $true
Start-Sleep -milliseconds 500
#Remove all licenses from the account
Foreach ($license in $licenses){
Set-MsolUserLicense -UserPrincipalName $user.UserPrincipalName -RemoveLicense $license.AccountSkuId
Start-Sleep -milliseconds 500
}
}
I had a look at that article. I'm not running anything crazy, it's all updates on individual mailboxes. Yes we do have 12,000+ mailboxes. But this script was only processing a few accounts., see below:
$users = Import-CSV "C:\mydir\list.csv"
Foreach ($user in $users){
$user.UserPrincipalName
#Convert mailbox to shared and hide from the address list
Set-Mailbox -identity $user.UserPrincipalName -Type shared -HiddenFromAddressListsEnabled $true
Start-Sleep -milliseconds 500
#Get the list of licences
$licenses = Get-MsolUser -UserPrincipalName $user.UserPrincipalName | select -ExpandProperty licenses
Start-Sleep -milliseconds 500
#Block sign-in to the account
Set-MsolUser -UserPrincipalname $user.UserPrincipalName -UsageLocation IE -BlockCredential $true
Start-Sleep -milliseconds 500
#Remove all licenses from the account
Foreach ($license in $licenses){
Set-MsolUserLicense -UserPrincipalName $user.UserPrincipalName -RemoveLicense $license.AccountSkuId
Start-Sleep -milliseconds 500
}
}