Last active
June 26, 2023 11:33
-
-
Save davehax/bf60c002bd58faf65f067cf8e27f422d to your computer and use it in GitHub Desktop.
This is an example script that uses the Client Side Object Model (CSOM) in PowerShell to get the "Everyone except external users" Principal.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$siteUrl = "https://mysharepointsite.sharepoint.com/sites/subsite" | |
# Set headers | |
$headers = @{ | |
"Authorization"="Bearer "; | |
} | |
$authRealm = ""; | |
# Make an invalid request. We will extract the GUID from the Response. | |
try { | |
Invoke-WebRequest $("$siteUrl/_vti_bin/client.svc") -Method POST -Headers $headers | |
} | |
catch [exception] { | |
# Extract Authentication Realm GUID from Response headers | |
$_.Exception.Response.Headers["WWW-Authenticate"] -match '(?<=Bearer realm=")\w+-\w+-\w+-\w+-\w+(?=")' | |
$authRealm = $matches[0]; | |
} | |
$everyoneExceptExternal = "c:0-.f|rolemanager|spo-grid-all-users/$authRealm" | |
$everyoneExceptExternalPrincipal = $web.EnsureUser($everyoneExceptExternal); | |
$ctx.Load($everyoneExceptExternalPrincipal); | |
$ctx.ExecuteQuery(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In line 20, what is the value of $web?