SharePoint online PnP command to find users and delete it if exists #3953
Unanswered
santoshsubedi10
asked this question in
Q&A
Replies: 1 comment
-
The command Remove-PnPUser checks for the user in the site and then removes it. If the user is not on the site, it will throw an error. The groups "Everyone" and "Everyone except external users" are registered in all sites by default, even if they don't have any permissions. You will find it in all the sites. The $UserID for Everyone is wrong. You can check the correct LoginName easily from SharePoint. I think it's "c:0(.s|true". |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am trying to create a script where it runs on site collection to find certain users. (ex 'Everyone' and 'everyone except external').
If those users doesn't exist, do nothing but if those exist, remove the user.
I figured how to remove a user. But how do i scan the users and then remove it all at once ?
$SiteURL = "https://test"
$UserID= ("everyone")
Connect-PnPOnline -Url $SiteUrl -UseWebLogin
$User = Get-PnPUser -Identity $UserID
if ($User)
{
Remove-PnPUser -Identity $UserID
Write-host -f Green "Removed User $UserID from the site!"
}
Else
{
Write-host -f Yellow "User $UserID doesn't exist on the site!"
Beta Was this translation helpful? Give feedback.
All reactions