SOLVED

Set-SPOSite -SharingCapability not changing when used with PowerShell

Steel Contributor

Hi All,

 

I've got the following script which when I run it against a site doesn't change the SharingCapability setting.

Any suggestions greatly appreciated:

Set-SPOSite -Identity "https://MyTenant.sharepoint.com/sites/MySiteAddress" -SharingCapability ExternalUserSharingOnly

If I can get this one line to run, and the value to change from ExistingExternalUserSharingOnly then I want to run it against all the sites in my tenancy so that they have cconsistent settings using the following script. 

NOTE My tenancy has the external sharing setting of "New and existing guests" level set. So to my mind I'm only changing some sites to be the same as the tenant's least permissive setting.

 

# This script gets all the sites in our tenancy.
# then checks what their SharingCapability setting is set to
# if it is set to ExistingExternalUserSharingOnly then that site will be changed to ExternalUserSharingOnly


$adminUPN="domainadmin@mytennant.onmicrosoft.com"

$orgName="MyTenant"

$userCredential = Get-Credential -UserName $adminUPN -Message "Type the password."

Connect-SPOService -Url https://$orgName-admin.sharepoint.com -Credential $userCredential



#get all the sites 
$AllSites = get-sposite -Limit all
$myArray = [System.Collections.ArrayList]@()
 
foreach ($url in $AllSites.url)
{
 
#Get all the site's details into an object
$myarray = get-sposite -identity $url -detailed 
 
#print the results and save if needed 
#$myarray | select url,SharingCapability | Export-Csv -path "C:\temp\allsites-sharing.csv" -append


#for testing
#$myarray.url 
#$myarray.SharingCapability

#get the current SharingCapability value
$thisValue = ($myarray.SharingCapability | Out-String).Trim()

#test the SharingCapability value and change if required
if ($thisValue -eq "ExistingExternalUserSharingOnly") {
		#write-host "Existing" so change to ExternalUserSharingOnly
		set-sposite -Identity $myArray.url -SharingCapability  ExternalUserSharingOnly
		write-host $myarray.url+" changed to ExternalUserSharingOnly"
	} else {
		#write-host "no change"
		write-host $myarray.url+"
	}

$thisValue=""

}
3 Replies
best response confirmed by Dorje McKinnon (Steel Contributor)
Solution

Hi @Dorje McKinnon,

 

There is a known regression in the SharePoint Online Management Shell. Please update to the newest version and that should fix it! Thanks!

 

Stephen Rice

Senior Program Manager, OneDrive

Hi @Stephen Rice 

 

thanks so much. Happier here in the South Pacific now :)

Hi @Dorje McKinnon,

 

Glad to hear it! Thanks!


Stephen Rice

1 best response

Accepted Solutions
best response confirmed by Dorje McKinnon (Steel Contributor)
Solution

Hi @Dorje McKinnon,

 

There is a known regression in the SharePoint Online Management Shell. Please update to the newest version and that should fix it! Thanks!

 

Stephen Rice

Senior Program Manager, OneDrive

View solution in original post