SOLVED

Read-only after migration

%3CLINGO-SUB%20id%3D%22%5C%26quot%3Blingo-sub-3165209%5C%26quot%3B%22%20slang%3D%22%5C%26quot%3Ben-US%5C%26quot%3B%22%3ERead-only%20after%20migration%26lt%3B%5C%2Flingo-sub%26gt%3B%3CLINGO-BODY%20id%3D%22%5C%26quot%3Blingo-body-3165209%5C%26quot%3B%22%20slang%3D%22%5C%26quot%3Ben-US%5C%26quot%3B%22%3E%3CP%3EHi%2C%26lt%3B%5C%2FP%26gt%3B%3C%2FP%3E%3CP%3ELooking%20for%20a%20way%20to%20place%20several%20hundreds%20of%20teams%20(mainly%20their%20SharePoint%20team%20sites)%20in%20read-only%20state%20after%20having%20migrated%20these%20from%20one%20tenant%20to%20another.%3CBR%20%2F%3E%3CBR%20%2F%3E%26lt%3B%5C%2FP%26gt%3B%3C%2FP%3E%3CP%3EBeen%20trying%20with%20the%20following%20script%2C%20but%20having%20no%20luck.%20Am%20I%20missing%20something%3F%20Or%20is%20it%20not%20possible%20to%20do%20this%20in%20a%20bulk%20operation%3F%26lt%3B%5C%2FP%26gt%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26lt%3B%5C%2FP%26gt%3B%3CPRE%20class%3D%22%5C%26quot%3Blia-code-sample%22%20language-powershell%3D%22%22%3E%3CCODE%3E%24AdminCenterURL%20%3D%20%5C%22https%3A%2F%2Ftenant-admin.sharepoint.com%5C%22%5Cn%24sites%20%3D%20Get-SPOSite%20-Limit%20All%20-Filter%20%7B%20Url%20-notlike%20%5C%22*-my.sharepoint.com*%5C%22%20%7D%20%20%20%23%20Get%20all%20sites%20excluding%20onedrive%5Cn%5CnConnect-SPOService%20-url%20%24AdminCenterURL%5CnSet-SPOSite%20%24sites%20-LockState%20%5C%22ReadOnly%5C%22%26lt%3B%5C%2Fcode%26gt%3B%26lt%3B%5C%2Fpre%26gt%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26lt%3B%5C%2FP%26gt%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26lt%3B%5C%2FP%26gt%3B%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%22%5C%26quot%3B2%5C%26quot%3B%22%20color%3D%22%5C%26quot%3B%23993300%5C%26quot%3B%22%3ESet-SPOSite%20%3A%20Cannot%20convert%20'System.Object%5B%5D'%20to%20the%20type%20'Microsoft.Online.SharePoint.PowerShell.SpoSitePipeBind'%20req%26lt%3B%5C%2FFONT%26gt%3B%3CBR%20%2F%3E%3CFONT%20size%3D%22%5C%26quot%3B2%5C%26quot%3B%22%20color%3D%22%5C%26quot%3B%23993300%5C%26quot%3B%22%3Euired%20by%20parameter%20'Identity'.%20Specified%20method%20is%20not%20supported.%26lt%3B%5C%2FFONT%26gt%3B%3CBR%20%2F%3E%3CFONT%20size%3D%22%5C%26quot%3B2%5C%26quot%3B%22%20color%3D%22%5C%26quot%3B%23993300%5C%26quot%3B%22%3EAt%20line%3A1%20char%3A13%26lt%3B%5C%2FFONT%26gt%3B%3CBR%20%2F%3E%3CFONT%20size%3D%22%5C%26quot%3B2%5C%26quot%3B%22%20color%3D%22%5C%26quot%3B%23993300%5C%26quot%3B%22%3E%2B%20Set-SPOSite%20%24sites%20-LockState%20%22ReadOnly%22%26lt%3B%5C%2FFONT%26gt%3B%3CBR%20%2F%3E%3CFONT%20size%3D%22%5C%26quot%3B2%5C%26quot%3B%22%20color%3D%22%5C%26quot%3B%23993300%5C%26quot%3B%22%3E%2B%20~~~~~~%26lt%3B%5C%2FFONT%26gt%3B%3CBR%20%2F%3E%3CFONT%20size%3D%22%5C%26quot%3B2%5C%26quot%3B%22%20color%3D%22%5C%26quot%3B%23993300%5C%26quot%3B%22%3E%2B%20CategoryInfo%20%3A%20InvalidArgument%3A%20(%3A)%20%5BSet-SPOSite%5D%2C%20ParameterBindingException%26lt%3B%5C%2FFONT%26gt%3B%3CBR%20%2F%3E%3CFONT%20size%3D%22%5C%26quot%3B2%5C%26quot%3B%22%20color%3D%22%5C%26quot%3B%23993300%5C%26quot%3B%22%3E%2B%20FullyQualifiedErrorId%20%3A%20CannotConvertArgument%2CMicrosoft.Online.SharePoint.PowerShell.SetSite%26lt%3B%5C%2FFONT%26gt%3B%26lt%3B%5C%2FP%26gt%3B%3C%2FFONT%3E%3C%2FFONT%3E%3C%2FFONT%3E%3C%2FFONT%3E%3C%2FFONT%3E%3C%2FFONT%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26lt%3B%5C%2FP%26gt%3B%3C%2FP%3E%3CP%3EOr%20is%20there%20another%20preferred%20approach%3F%20Thanks!%26lt%3B%5C%2FP%26gt%3B%26lt%3B%5C%2Flingo-body%26gt%3B%3CLINGO-LABS%20id%3D%22%5C%26quot%3Blingo-labs-3165209%5C%26quot%3B%22%20slang%3D%22%5C%26quot%3Ben-US%5C%26quot%3B%22%3E%3CLINGO-LABEL%3EPowerShell%26lt%3B%5C%2Flingo-label%26gt%3B%3CLINGO-LABEL%3ESharePoint%20Online%26lt%3B%5C%2Flingo-label%26gt%3B%26lt%3B%5C%2Flingo-labs%26gt%3B%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3C%2FLINGO-SUB%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3165209%22%20slang%3D%22en-US%22%3ERead-only%20after%20migration%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3165209%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3ELooking%20for%20a%20way%20to%20place%20several%20hundreds%20of%20teams%20(mainly%20their%20SharePoint%20team%20sites)%20in%20read-only%20state%20after%20having%20migrated%20these%20from%20one%20tenant%20to%20another.%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3EBeen%20trying%20with%20the%20following%20script%2C%20but%20having%20no%20luck.%20Am%20I%20missing%20something%3F%20Or%20is%20it%20not%20possible%20to%20do%20this%20in%20a%20bulk%20operation%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24AdminCenterURL%20%3D%20%22https%3A%2F%2Ftenant-admin.sharepoint.com%22%0A%24sites%20%3D%20Get-SPOSite%20-Limit%20All%20-Filter%20%7B%20Url%20-notlike%20%22*-my.sharepoint.com*%22%20%7D%20%20%20%23%20Get%20all%20sites%20excluding%20onedrive%0A%0AConnect-SPOService%20-url%20%24AdminCenterURL%0ASet-SPOSite%20%24sites%20-LockState%20%22ReadOnly%22%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%20color%3D%22%23993300%22%3ESet-SPOSite%20%3A%20Cannot%20convert%20'System.Object%5B%5D'%20to%20the%20type%20'Microsoft.Online.SharePoint.PowerShell.SpoSitePipeBind'%20req%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%20color%3D%22%23993300%22%3Euired%20by%20parameter%20'Identity'.%20Specified%20method%20is%20not%20supported.%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%20color%3D%22%23993300%22%3EAt%20line%3A1%20char%3A13%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%20color%3D%22%23993300%22%3E%2B%20Set-SPOSite%20%24sites%20-LockState%20%22ReadOnly%22%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%20color%3D%22%23993300%22%3E%2B%20~~~~~~%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%20color%3D%22%23993300%22%3E%2B%20CategoryInfo%20%3A%20InvalidArgument%3A%20(%3A)%20%5BSet-SPOSite%5D%2C%20ParameterBindingException%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%20color%3D%22%23993300%22%3E%2B%20FullyQualifiedErrorId%20%3A%20CannotConvertArgument%2CMicrosoft.Online.SharePoint.PowerShell.SetSite%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOr%20is%20there%20another%20preferred%20approach%3F%20Thanks!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3165209%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Occasional Contributor

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!

2 Replies
best response confirmed by TH_ (Occasional Contributor)
Solution
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"

}
Thank you so much, works like a charm!