Announcement

Collapse
No announcement yet.

Move Home Folders to Archived location

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Move Home Folders to Archived location

    Each month we disable a significant amount of user accounts in our Windows 2003 environment. When we do this, we would like to run a script that will read a CSV file to move the folder from their original location to the new, archived destination (on the same server).

    Theoretically, the csv would be as follows
    \\serverA\%username% \\serverA\Arcive\%username
    \\serverB\%username% \\serverB\Arcive\%username

    What is the best way to do this? Do we need to do this individually (easy enough) or is there a scripting lanugage we should use, VBS, powershell or even Robocopy?

    We've looked at powershell, the move-item, but unfortunately, I'm not sure how to have it read a CSV and respond to that. Any guidance is appreciated!

    TIA.

  • #2
    Re: Move Home Folders to Archived location

    Originally posted by cmj0002 View Post
    we would like to run a script that will read a CSV file to move the folder from their original location to the new, archived destination (on the same server).
    The exact way for parsing CSV file depends on the file format, but a regex would surely do. Here is a quick and dirty take for taking the old and new directories apart and launching move-item for the directories. If the output seems reasonable enough, remove the -whatif switch.

    Code:
    # Read the CSV file into a variable
    $dirs = get-content "archived.csv"
    
    # If file has no content, give up
    if ($dirs.length -lt 1)
    {
        write-host "No dirs to archive at all."
        exit
    }
    
    # Iterate each row
    foreach($d in $dirs)
    {
        # Look for share combos. Change the regexp to suite your needs.
        $pattern = '(?i)^([a-z_\\]*)[ ]([a-z_\\]*)$'
        
        # Get first and second substring
        $old = [regex]::replace($d, $pattern, '$1')
        $new = [regex]::replace($d, $pattern, '$2')
        
        # Move stuff around
        move-item -whatif $old $new
    }
    -vP

    Comment

    Working...
    X