1

Having trouble find any resources for using Powershell to remove and re-add an user account for site visitors. I have 80+ sites where I need to iterate through and remove the current visitor account and re-add it to update them to the new role provider. Not sure what best practice is on this but was hoping I could automate this through Powershell instead of manually going to each collection and removing and re-adding the account.

enter image description here

enter image description here

2

Instead of removing and re-adding you may be able to just update their accounts.

Move-SPUser -Identity "c:0-.f|atschoolroleprovider|parent" -NewAlias "c:0-.f|nhaschoolsauthroleprovider|parent"

You can use the Get-SPUser to get all users and then loop over them to run across multiple accounts.

1

to remove a user try this one

######################## Start Variables ########################
$LoginName = "domain\login"
$siteURL = "http://SharePointSiteURL" #URL to any site in the web application.
######################## End Variables ########################
Clear-Host
$siteCount = 0
[system.reflection.assembly]::loadwithpartialname("Microsoft.SharePoint")
$site = new-object microsoft.sharepoint.spsite($siteURL)
$webApp = $site.webapplication
$allSites = $webApp.sites
foreach ($site in $allSites)
{

    $web = $site.openweb()
    $web.SiteUsers.Remove($LoginName)
    $web.Dispose()
    $siteCount++
}
$site.dispose()
write-host "Updated" $siteCount "Site Collections."

Remove a single user from all site collections in a web application using powershell

for adding a user, please check this http://get-spscripts.com/2011/02/add-sharepoint-or-ad-groupuser-to-all.html

I think you have to tweak it as per you requirement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.