Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Looking to fix my powershell script for updating secondary site administrators in Sharepoint Online

$
0
0

I'm not a professional at this and I didn't even stay in a holiday inn last night, so I'm hoping to get some assistance with a script... or maybe a good suggestion for how we can easily resolve a problem that I'm hoping to "automate" a little bit.

The issue?  We have a process when we create sites in O365 / Sharepoint Online that we create the sites and list members of our team as secondary admins on all sites.  Works good until you realize that someone could forget to do this or we have new people come to the team. Then you've got a bunch of admins missing from the sites.  Not good when that comes to using a 3rd party utility that is not showing sites you aren't listed as a secondary admin on.

We created a simple powershell script.  Then we started to think of ways to make it more universal... we started by exporting a list of our sites to a CSV file and using that list of sites to run a command against.  Now we're hoping to have the script grab the list of sites so dynamically we wouldn't have to update our CSV file just to get every new site.

But that is where it broke down.  What I have so far is below.  Before I tried to modify this we simply read the CSV and had most of the same code and it worked great.  

Hoping to get input for the user who we want to grant access to.  Get a list of our SP Online sites.  For each of those sites we would set the user to $true, indicating they are a collection admin.  The other ($str) string was just fluff so I could see it as it went through the list.

$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
}

Unfortunately it ends up with this error for every site it reads:

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

Someone suggested that it may need to force that array element into a string, but we tried a couple things there that failed to do anything.  

Any thoughts?


Bill


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>