Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This wiki is based on the Forum Post How to update secondary site collection Administrator to all Site Collections
Code OP used:
$Cred=read-host -Prompt "LANID@hermanmiller.com of user you wish to grant access to all site collections.";
$collection=get-sposite | select Url
ForEach ($Url in $collection)
{
$str = " "
Set-SPOUser -site $Url -loginName $Cred -IsSiteCollectionAdmin $True
$str += "Added to - " + $Url
echo $str
}
Error:
Set-SPOUser : Cannot bind parameter 'Site'. Cannot convert the "@{Url=https://oursite.sharepoint.com/parth/path}" value of type "Selected.Microsoft.Online.SharePoint.PowerShell.SPOSite" to type "Microsoft.Online.SharePoint.PowerShell.SpoSitePipeBind". At C:\Powershell\Site Access\sites1.ps1:10 char:19 + Set-SPOUser -site $Url -loginName $Cred -IsSiteCollectionAdmin $True + ~~~~ + CategoryInfo : InvalidArgument: (:) [Set-SPOUser], ParameterBin dingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Online. SharePoint.PowerShell.SetSPOUser Indeed PowerShell is doing it's job, however we need to manipulate and feed inputs. Glitch here is the OutPut "@{Url=https://oursite.sharepoint.com/parth/path}"
Refer the Screen Shot attached by OP in the Forum. [That solves the issue]
Solution:
$Cred=read-host -Prompt "LANID@hermanmiller.com of user you wish to grant access to all site collections.";
$collection=get-sposite -Limit All
ForEach ($Url in $collection.url)
{
$str = " "
Set-SPOUser -site $Url -loginName $Cred -IsSiteCollectionAdmin $True
$str += "Added to - " + $Url
echo $str
}
Bingo - It worked. :)
How does this work? The Variable $Collection is holding a bunch of property values. To meet our requirement, we need to select only the URL.