Forum Discussion

TH_'s avatar
TH_
Copper Contributor
Feb 14, 2022
Solved

Read-only after migration

Hi,

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 = "https://tenant-admin.sharepoint.com"
$sites = Get-SPOSite -Limit All -Filter { Url -notlike "*-my.sharepoint.com*" }   # 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!

  • Hello!
    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"

    }
  • Hello!
    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"

    }
    • TH_'s avatar
      TH_
      Copper Contributor
      Thank you so much, works like a charm!

Resources