SOLVED

Turning off sharing with externals on all sharepoint sites, teams and groups?

%3CLINGO-SUB%20id%3D%22lingo-sub-1474823%22%20slang%3D%22en-US%22%3ETurning%20off%20sharing%20with%20externals%20on%20all%20sharepoint%20sites%2C%20teams%20and%20groups%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1474823%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20looking%20to%20see%20if%20it's%20possible%20thru%20powershell%20to%20turn%20off%20the%20sharing%20capability%20of%20all%20sharepoint%20sites.%20groups%20and%20team%20sites%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt's%20very%20hard%20to%20go%20thru%20every%2030%20sharepoint%20sites%2Fgroups%20and%20edit%20bulking%20them%20when%20there's%20over%201%2C000.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20what%20I%20mean....%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22bulk%20editing%20in%20%20powershell.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F199540iEF3FA953B8A6ECDF%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22bulk%20editing%20in%20%20powershell.png%22%20alt%3D%22bulk%20editing%20in%20powershell.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22bulkediting2.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F199541i184D43F3C36AF0F5%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22bulkediting2.png%22%20alt%3D%22bulkediting2.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EIs%20it%20possible%20to%20do%20in%20PowerShell%3F%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1474823%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EOffice%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOffice%20365%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1479755%22%20slang%3D%22en-US%22%3ERe%3A%20Turning%20off%20sharing%20with%20externals%20on%20all%20sharepoint%20sites%2C%20teams%20and%20groups%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1479755%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F326922%22%20target%3D%22_blank%22%3E%40Odenkaz%3C%2FA%3E%26nbsp%3BHello%20Odenkaz.%20As%20far%20as%20I%20know%2C%20everything%20can%20be%20done%20through%20PowerShell%20if%20you%20try%20and%20test%20enough%20%3D)%2C%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHope%20this%20solves%20your%20request%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24AllSitesURLs%20%3D%20%24(Get-SPOSite%20%7C%20where%7B%24_.status%20-eq%20'Active'%7D).URL%20%23You%20can%20play%20with%20the%20filter%20to%20set%20only%20those%20sites%20that%20you%20require%0A%0AForeach(%24SiteURL%20in%20%24AllSitesURLs)%0A%20%7B%0A%20%20Set-SPOSite%20-Identity%20%24SiteURL%20-SharingCapability%20Disabled%20%23Here%20you%20can%20set%20the%20sharing%20options%20that%20you%20consider%20better.https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsharepoint%2Fturn-external-sharing-on-or-off%20%0A%20%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERegards%3C%2FP%3E%3CP%3EErick%20Moreno%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1479773%22%20slang%3D%22en-US%22%3ERe%3A%20Turning%20off%20sharing%20with%20externals%20on%20all%20sharepoint%20sites%2C%20teams%20and%20groups%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1479773%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CBLOCKQUOTE%3E%3CHR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F89674%22%20target%3D%22_blank%22%3E%40Erick%20A.%20Moreno%20R.%3C%2FA%3E%26nbsp%3Bwrote%3A%3CBR%20%2F%3E%3CP%3E-ERR%3AREF-NOT-FOUND-%40Odenkaz%26nbsp%3BHello%20Odenkaz.%20As%20far%20as%20I%20know%2C%20everything%20can%20be%20done%20through%20PowerShell%20if%20you%20try%20and%20test%20enough%20%3D)%2C%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHope%20this%20solves%20your%20request%3A%3C%2FP%3E%3C%2FBLOCKQUOTE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24AllSitesURLs%20%3D%20%24(Get-SPOSite%20%7C%20where%7B%24_.status%20-eq%20'Active'%7D).URL%20%23You%20can%20play%20with%20the%20filter%20to%20set%20only%20those%20sites%20that%20you%20require%0A%0AForeach(%24SiteURL%20in%20%24AllSitesURLs)%0A%20%7B%0A%20%20Set-SPOSite%20-Identity%20%24SiteURL%20-SharingCapability%20Disabled%20%23Here%20you%20can%20set%20the%20sharing%20options%20that%20you%20consider%20better.https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsharepoint%2Fturn-external-sharing-on-or-off%20%0A%20%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERegards%3C%2FP%3E%3CP%3EErick%20Moreno%3C%2FP%3E%3CHR%20%2F%3E%3CP%3EHi%20Erick%2C%20thank%20you%20for%20your%20reply!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20tried%20your%20snippet%20and%20got%20the%20following%20error%3A%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Odenkaz_0-1592779407331.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F199947i1A38CD1C69A9BE84%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22Odenkaz_0-1592779407331.png%22%20alt%3D%22Odenkaz_0-1592779407331.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAdditionally%3A%20To%20filter%20only%20those%20with%20external%20sharing%20enabled%20i%20would%20have%20to%20add%20in%20the%20where%20clause%20the%20exact%20name%20of%20the%20column%20shown%20in%20the%20report%3F%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1479783%22%20slang%3D%22en-US%22%3ERe%3A%20Turning%20off%20sharing%20with%20externals%20on%20all%20sharepoint%20sites%2C%20teams%20and%20groups%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1479783%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F326922%22%20target%3D%22_blank%22%3E%40Odenkaz%3C%2FA%3E%26nbsp%3B%20This%20should%20filter%20those%20that%20are%20throwing%20the%20error.%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24AllSitesURLs%20%3D%20%24(Get-SPOSite%20%7C%20where%7B%24_.status%20-eq%20'Active'%20-and%20%24_.Template%20-notlike%20%22SPSMSITEHOST*%22%20-and%20%24_.Template%20-notlike%20%22POINTPUBLISHINGHUB*%22%7D).URL%20%23You%20can%20play%20with%20the%20filter%20to%20set%20only%20those%20sites%20that%20you%20require%0A%0AForeach(%24SiteURL%20in%20%24AllSitesURLs)%0A%20%7B%0A%20%20Set-SPOSite%20-Identity%20%24SiteURL%20-SharingCapability%20Disabled%20%23Here%20you%20can%20set%20the%20sharing%20options%20that%20you%20consider%20better.https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsharepoint%2Fturn-external-sharing-on-or-off%20%0A%20%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EAs%20you%20said%2C%20you%20just%20need%20to%20combine%20the%20attributes%2Fcolumns%20using%20the%20format%20I%20used%20above%20and%20the%20desired%20state%20on%20each%20one%20to%20set%20the%20sharing%20options%20only%20for%20those%20that%20meet%20the%20conditions.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERegards%3C%2FP%3E%3CP%3EErick%20Moreno%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1479883%22%20slang%3D%22en-US%22%3ERe%3A%20Turning%20off%20sharing%20with%20externals%20on%20all%20sharepoint%20sites%2C%20teams%20and%20groups%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1479883%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F89674%22%20target%3D%22_blank%22%3E%40Erick%20A.%20Moreno%20R.%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%20Erick%2C%3C%2FP%3E%3CP%3EThanks%20for%20the%20help!%3C%2FP%3E%3CP%3EI%20have%20a%20doubt.%20Did%20you%20use%20the%20Template%20IDs%3F%20If%20so%2C%20what%20is%20the%20ID%20for%20modern%20team%20sites%3F%3C%2FP%3E%3CP%3EI'm%20trying%20to%20play%20around%20with%20the%20snippet%20you%20shared%20and%20it's%20not%20disabling%20sharing%20for%20team%20sites.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eis%20the%20code%20for%20modern%20team%20site%3A%20STS%233%3F%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1479921%22%20slang%3D%22en-US%22%3ERe%3A%20Turning%20off%20sharing%20with%20externals%20on%20all%20sharepoint%20sites%2C%20teams%20and%20groups%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1479921%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F326922%22%20target%3D%22_blank%22%3E%40Odenkaz%3C%2FA%3E%26nbsp%3BI%20think%20so%20by%20what%20is%20described%20here%3A%26nbsp%3B%3CA%20title%3D%22Modern%20Site%20Provisioning%22%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsharepoint%2Fdev%2Fsolution-guidance%2Fmodern-experience-customizations-provisioning-sites%23provisioning-modern-team-sites%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EModern%20Site%20Provisioning%3C%2FA%3E%3C%2FP%3E%3CP%3EBut%2C%20after%20reading%20your%20original%20post%20I%20think%20the%20problem%20is%20the%20default%20limit(200)%20for%20the%20output%2C%20please%20add%20the%20%22-limit%20All%22%20to%20the%20get-SPOSite%20cmdlet.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24AllSitesURLs%20%3D%20%24(Get-SPOSite%20-Limit%20All%20%7C%20where%7B%24_.status%20-eq%20'Active'%20-and%20%24_.Template%20-notlike%20%22SPSMSITEHOST*%22%20-and%20%24_.Template%20-notlike%20%22POINTPUBLISHINGHUB*%22%7D).URL%20%23You%20can%20play%20with%20the%20filter%20to%20set%20only%20those%20sites%20that%20you%20require%0A%0A%24Count%20%3D%20%24AllSitesURLs.count%0AWrite-Host%20'Total%20Sites%20Gathered'%20%24Count%20-Foreground%20Cyan%0AForeach(%24SiteURL%20in%20%24AllSitesURLs)%0A%20%7B%0A%20%20Set-SPOSite%20-Identity%20%24SiteURL%20-SharingCapability%20Disabled%20%23Here%20you%20can%20set%20the%20sharing%20options%20that%20you%20consider%20better.https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsharepoint%2Fturn-external-sharing-on-or-off%20%0A%20%7D%0A%0A%20%24STS3Sites%20%3D%20Get-SPOSite%20-Limit%20All%20-Template%20'STS%233'%20%23filter%20by%20template%2C%20it%20is%20easier%20with%20the%20template%20switch%0A%0A%20%24AllTemplates%20%3D%20Get-SPOSite%20-Limit%20All%20%7C%20select%20Template%20-Unique%20%23%20just%20to%20know%20what%20are%20the%20templates%20that%20you%20are%20using%20on%20your%20tenant.%20%3D)%3C%2Fimg%3E%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%26nbsp%3B%20%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

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....

 

bulk editing in  powershell.png

bulkediting2.png

Is it possible to do in PowerShell? 

 

5 Replies
Highlighted

@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

Highlighted

 


@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:

Odenkaz_0-1592779407331.png

 

 

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? 

 

Highlighted

@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  

Highlighted

@Erick A. Moreno R. 

 

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? 

 

Highlighted
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. =)