Jun 18 2020 10:08 AM
Hi,
I am looking to see if it's possible thru powershell to turn off the sharing capability of all sharepoint sites. groups and team sites?
It's very hard to go thru every 30 sharepoint sites/groups and edit bulking them when there's over 1,000.
This what I mean....
Is it possible to do in PowerShell?
Jun 21 2020 03:07 PM
@Odenkaz Hello Odenkaz. As far as I know, everything can be done through PowerShell if you try and test enough =),
Hope this solves your request:
$AllSitesURLs = $(Get-SPOSite | where{$_.status -eq 'Active'}).URL #You can play with the filter to set only those sites that you require
Foreach($SiteURL in $AllSitesURLs)
{
Set-SPOSite -Identity $SiteURL -SharingCapability Disabled #Here you can set the sharing options that you consider better.https://docs.microsoft.com/en-us/sharepoint/turn-external-sharing-on-or-off
}
Regards
Erick Moreno
Jun 21 2020 03:46 PM - edited Jun 21 2020 03:54 PM
@Erick A. Moreno R. wrote:@Odenkaz Hello Odenkaz. As far as I know, everything can be done through PowerShell if you try and test enough =),
Hope this solves your request:
$AllSitesURLs = $(Get-SPOSite | where{$_.status -eq 'Active'}).URL #You can play with the filter to set only those sites that you require
Foreach($SiteURL in $AllSitesURLs)
{
Set-SPOSite -Identity $SiteURL -SharingCapability Disabled #Here you can set the sharing options that you consider better.https://docs.microsoft.com/en-us/sharepoint/turn-external-sharing-on-or-off
}
Regards
Erick Moreno
Hi Erick, thank you for your reply!
I tried your snippet and got the following error:
Additionally: To filter only those with external sharing enabled i would have to add in the where clause the exact name of the column shown in the report?
Jun 21 2020 04:20 PM
@Odenkaz This should filter those that are throwing the error.
$AllSitesURLs = $(Get-SPOSite | where{$_.status -eq 'Active' -and $_.Template -notlike "SPSMSITEHOST*" -and $_.Template -notlike "POINTPUBLISHINGHUB*"}).URL #You can play with the filter to set only those sites that you require
Foreach($SiteURL in $AllSitesURLs)
{
Set-SPOSite -Identity $SiteURL -SharingCapability Disabled #Here you can set the sharing options that you consider better.https://docs.microsoft.com/en-us/sharepoint/turn-external-sharing-on-or-off
}
As you said, you just need to combine the attributes/columns using the format I used above and the desired state on each one to set the sharing options only for those that meet the conditions.
Regards
Erick Moreno
Jun 21 2020 07:28 PM
Hi Erick,
Thanks for the help!
I have a doubt. Did you use the Template IDs? If so, what is the ID for modern team sites?
I'm trying to play around with the snippet you shared and it's not disabling sharing for team sites.
is the code for modern team site: STS#3?
Jun 21 2020 08:24 PM
Solution@Odenkaz I think so by what is described here: Modern Site Provisioning
But, after reading your original post I think the problem is the default limit(200) for the output, please add the "-limit All" to the get-SPOSite cmdlet.
$AllSitesURLs = $(Get-SPOSite -Limit All | where{$_.status -eq 'Active' -and $_.Template -notlike "SPSMSITEHOST*" -and $_.Template -notlike "POINTPUBLISHINGHUB*"}).URL #You can play with the filter to set only those sites that you require
$Count = $AllSitesURLs.count
Write-Host 'Total Sites Gathered' $Count -Foreground Cyan
Foreach($SiteURL in $AllSitesURLs)
{
Set-SPOSite -Identity $SiteURL -SharingCapability Disabled #Here you can set the sharing options that you consider better.https://docs.microsoft.com/en-us/sharepoint/turn-external-sharing-on-or-off
}
$STS3Sites = Get-SPOSite -Limit All -Template 'STS#3' #filter by template, it is easier with the template switch
$AllTemplates = Get-SPOSite -Limit All | select Template -Unique # just to know what are the templates that you are using on your tenant. =)
Jun 21 2020 08:24 PM
Solution@Odenkaz I think so by what is described here: Modern Site Provisioning
But, after reading your original post I think the problem is the default limit(200) for the output, please add the "-limit All" to the get-SPOSite cmdlet.
$AllSitesURLs = $(Get-SPOSite -Limit All | where{$_.status -eq 'Active' -and $_.Template -notlike "SPSMSITEHOST*" -and $_.Template -notlike "POINTPUBLISHINGHUB*"}).URL #You can play with the filter to set only those sites that you require
$Count = $AllSitesURLs.count
Write-Host 'Total Sites Gathered' $Count -Foreground Cyan
Foreach($SiteURL in $AllSitesURLs)
{
Set-SPOSite -Identity $SiteURL -SharingCapability Disabled #Here you can set the sharing options that you consider better.https://docs.microsoft.com/en-us/sharepoint/turn-external-sharing-on-or-off
}
$STS3Sites = Get-SPOSite -Limit All -Template 'STS#3' #filter by template, it is easier with the template switch
$AllTemplates = Get-SPOSite -Limit All | select Template -Unique # just to know what are the templates that you are using on your tenant. =)