locked
Script to copy User Roaming profile to new location RRS feed

  • Question

  • Hi,

    I have to move the "My Documents" folder in  about 100 users roaming profile to a new profile that has been created.

    i.e. copy from \\windows2003server\d$\profile\%username%\documets

    to

    \\windows2003server\d$\profile\%username%.new\documents

     

    Both the locations are on the same server.

    Any Help would be appreciated

    Leandro

    Thursday, April 28, 2011 11:56 AM

Answers

  • Here is a simple powershell script that will basically perform what you ask. Edit the $folders variable to point to the root of your user profiles.

     

    # Get list of sub folders from the profile directory
    $Folders = get-childitem "d:\profile"
    
    Foreach ($Folder in $Folders)
    {
    # Show a progress bar.
      write-progress -activity "Moving My Documents" -status $Folder -percentcomplete (([array]::indexOf($folders, $folder)) / $folders.count * 100)
    
    # Test that there is a Folder called documents
      If (Test-Path ($Folder.fullname + "\Documents"))
      {
    
    # Move each folder from the original location to new location. Use the -WhatIf switch if unsure of outcome.
        Move-Item ($Folder.fullname + "\Documents") -Destination ($Folder.fullname + ".new\Documents")
    
      } # End If
    } # End Foreach
    

    • Marked as answer by IamMred Friday, May 27, 2011 5:43 AM
    Tuesday, May 17, 2011 3:29 AM