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 $_

}

}

}

RemoveuserFromwebapplication.ps1 -LoginName “user1” -SiteUrl “http://spSite:8080/sites/site”