Couple of things.
Funcations:
Function RemoveUser($LoginName,$SiteUrl) { #Get site $Site = Get-SPSite | where {$_.url -eq $SiteUrl} If($Site) { $Web = $Site.openweb() Try { #Get user $user = $web.SiteUsers | where {$_.UserLogin -like "*$LoginName"} #Remove user if($user) { $web.SiteUsers.Remove($user) write-host "Remove user $LoginName from site '$SiteUrl' successfully." } Else { write-Warning "User $LoginName not found on site '$SiteUrl'." } } Catch { Write-Error $_ } } }
then run the command like this:
RemoveuserFromwebapplication.ps1 -LoginName "user1" -SiteUrl "http://win-chu4c2rckti:8080/sites/project"
How to remove certain user from a SharePoint site (PowerShell)
- When a user removed from SharePoint and all the documents or items created or modified by it, assign to system account.