none
Replace user(s) completely

    Question

  • Hi

    In a company where there's a lot of onboarding/offboarding of people.

    So having a lot of documents/list items etc. in various WebApps where SP has the users listed (that's no longer in the company)

    So as the MySite gives it to their manager automatic - this is not happening on the docs/list items 

    Instead SharePoint reports either the person as author and/or 'modified by'... 

    How do I 'replace' these users completely on the various docs and items?  

    Monday, May 01, 2017 6:19 AM

All replies

  • Hi

    you can use powershell to modify this information

    Add-PSSnapin Microsoft.SharePoint.Powershell
    $myweb=get-SPWeb "Your Web URL"
    $mylist=$myweb.Lists["Your List"]
    #this is the new username
    $replacedUser =$web.EnsureUser("domainName\Account")
    foreach($item in $mylist.Items)       
    {   
       ######### Author is <<Created by>>     
       $item["Author"] = $replacedUser   
       ######### Editor is <Modified by>>
       $item["Editor"] = $replacedUser   
       $item.update()        
    }        
    $myweb.Update()        
    $myweb.dispose()


    Romeo Donca, Orange Romania (MCSE, MCITP, CCNA) Please Mark As Answer if my post solves your problem or Vote As Helpful if the post has been helpful for you.

    Monday, May 01, 2017 7:12 AM
  • Hi Romeo 

    Thanks - but that will cause a lot of "manual" as I need to adjust to specific WebApp and list..  and users have +2500 documents various places 

    I need it for the "Farm level" 

    Monday, May 01, 2017 8:09 AM
  • hI

    foreach ($site  in (Get-SPWebApplication  | Get-SPSite))
    {
      ######## previous code
    
    }

    you should parse all site using


    Romeo Donca, Orange Romania (MCSE, MCITP, CCNA) Please Mark As Answer if my post solves your problem or Vote As Helpful if the post has been helpful for you.

    Monday, May 01, 2017 8:26 AM
  • Hi Romeo 

    Do I specify the user that needs replacement in the:
    $replacedUser =$web.EnsureUser("domainName\Account")

    otherwise where do I specify the user that is going instead of the replaced user?  

    #Find user that needs replaced

    $replaceTheUser =$web.EnsureUser("domainName\Account") 

    #Replace the user that is found with this user

    $newUser = ("domainName\Account") 

    Sorry but I'm a NOOB to syntax 

    Otherwise this should do it?; 

    Add-PSSnapin Microsoft.SharePoint.Powershell

    #this is the new username
    $replacedUser =$web.EnsureUser("domainName\Account")
    foreach ($site  in (Get-SPWebApplication  | Get-SPSite))     
    {   
       ######### Author is <<Created by>>     
       $item["Author"] = $replacedUser   
       ######### Editor is <Modified by>>
       $item["Editor"] = $replacedUser   
       $item.update()        
    }        
    $myweb.Update()        
    $myweb.dispose()



    • Edited by JmATK Monday, May 01, 2017 8:55 AM
    Monday, May 01, 2017 8:39 AM