SharePoint Online: Share Site to “Everyone Except External Users” using PowerShell
Requirement: Add everyone except external users in SharePoint Online
SharePoint Online: Share with Everyone Except External Users Group
I got a requirement to grant access to everyone in the organization to a SharePoint Online site. In SharePoint Online, you can share a site, document library, or individual document with “Everyone except external users.”
To share with everyone except external users, do the following:
- Login to your SharePoint Online site >> Click on the “Share” button in the top-right corner.
- In the Add user popup, Enter “Everyone Except External Users”, pick the relevant SharePoint group or permission for this group and click on Share.
You can also do this by going to Site Settings >> Click on “Site permissions” under “Users and Permissions” group >> Pick the group where you want to add everyone in your organization >> New >> Add Users >> Enter “Everyone except external users” >> Click on “Share”.
PowerShell to Add Everyone Except External Users in SharePoint Online
Alternatively, you can use PowerShell to share the site with “Everyone except external users”. Here is how to add everyone except external users to the site visitors group using PowerShell:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Set Variables
$SiteURL = "https://crescent.sharepoint.com/sites/Marketing"
#Get Credentials to connect
$Cred = Get-Credential
Try {
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
#Get the default visitors groups of the site
$VisitorsGroup = $ctx.web.AssociatedVisitorGroup
$Ctx.load($VisitorsGroup)
$Ctx.ExecuteQuery()
#Resolve User Name by Display Name
$Principal = [Microsoft.SharePoint.Client.Utilities.Utility]::ResolvePrincipal($Ctx, $Ctx.Web, "Everyone except external users", "All", "All", $Null, $True)
$Ctx.ExecuteQuery()
$User = $Ctx.Web.EnsureUser($Principal.Value.LoginName)
$Ctx.ExecuteQuery()
#Add user to the group
$VisitorsGroup.Users.AddUser($User) | Out-Null
$Ctx.ExecuteQuery()
}
catch {
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
PnP PowerShell to Add Everyone Except External Users to the Site
Let’s add everyone except external users to the Visitors group of the site with PnP PowerShell.
#Config Parameter
$SiteURL = "https://crescent.sharepoint.com/sites/marketing"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)
#Get the Group to Add - Default Visitors group of the site
$Group = Get-PnPGroup -AssociatedVisitorGroup
#Add Everyone except External Users to Visitors group
Add-PnPGroupMember -Identity $Group -LoginName "everyone except external users"
Conclusion
In conclusion, SharePoint Online allows you to share a site, document library, or individual document with “Everyone except external users.” This feature allows you to share content with everyone in your organization, while still maintaining security and privacy by excluding external users. The process of sharing with “Everyone except external users” can be done through the SharePoint UI or by using PowerShell.
thank you so much for the script. your blog is first hit in most PS issues.
Good morning. Firstly, I want to thank you for this site – your scripts have helped me on quite a few occasions. I have two questions.
Firstly, do you have an example script on how to *remove* the “Everyone” & “Everyone except external users” from all sites in a tenant? It seems my predecessor had added those groups to quite a few sites, and 2 years later it’s been found that people have been viewing information that they shouldn’t. We’ve decided to send out comms to let people know we’ll be removing those groups from all sites, and if they want them back to contact us. I just haven’t been able to figure out a script for doing it (and we have in the region of 15,000 sites in our tenant)
My second question is do you have an example for how to delete a specifically named file recursively through the subsites of a site? One of our businesses in the Netherlands has an executive site, with subsites for each board member. The structure of all the subsites is identical. The PA copies files to a folder on the root site, and then there’s a flow and some azure app that then copies the file to the same location on each subsite (again, this was done by my predecessor, and there’s no source code or any form of documentation on how it was built). What they would like to do is, if they upload a file with an exclamation mark at the beginning (eg !Document1.docx), then a script will run and DELETE the file called Document1.docx from each of the subsites. The explanation is that Document1.docx was uploaded in error, and they need to delete it, but no-one has access to all 17 board members’ subsites.
I would appreciate it if you could possibly point me in the right direction on these.
Thank you, and have a good day.
Hi FortyTwoWest,
1. You can find and delete these two accounts from all sites! How to Remove a User from All Sites in SharePoint Online using PowerShell, Use the Login names as: “c:0(.s|true” and “c:0-.f|rolemanager|spo-grid-all-users/$(Get-PnPTenantID)”
2. You can search for the specific file and delete it from all sites. How to Search SharePoint Online using PnP PowerShell?, Use the keyword as “filename:!Document1.docx”