Read-only after migration

Occasional Contributor


Looking for a way to place several hundreds of teams (mainly their SharePoint team sites) in read-only state after having migrated these from one tenant to another.

Been trying with the following script, but having no luck. Am I missing something? Or is it not possible to do this in a bulk operation?


$AdminCenterURL = ""
$sites = Get-SPOSite -Limit All -Filter { Url -notlike "**" }   # Get all sites excluding onedrive

Connect-SPOService -url $AdminCenterURL
Set-SPOSite $sites -LockState "ReadOnly"



Set-SPOSite : Cannot convert 'System.Object[]' to the type 'Microsoft.Online.SharePoint.PowerShell.SpoSitePipeBind' req
uired by parameter 'Identity'. Specified method is not supported.
At line:1 char:13
+ Set-SPOSite $sites -LockState "ReadOnly"
+ ~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-SPOSite], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,Microsoft.Online.SharePoint.PowerShell.SetSite


Or is there another preferred approach? Thanks!

2 Replies
best response confirmed by TH_ (Occasional Contributor)
You can't set the LockState to an array of $sites, you will have to do it for each one of them with a for loop, something like

foreach($site in $sites){

set-SPOSite $site.Url -LockState "ReadOnly"

Thank you so much, works like a charm!