posted 17/12/09

Function of the day – Move UserFolders

By Fredrik Wall

This function Is a Function on demand :)
And will be todays function gift to you all!

I wrote this right now for a friend of mine,
Stefan Schörling. He needed a script that will move
old users folders to another folder based on a text file.

This is a function that I wrote in 5 min, so It’s only the first version.

function Move-UserFolders {
    param ($userFile, $userFoldersPath, $userOld)
    $users = Get-Content $userFile
    foreach ($userFolder in $users) {
        $userFullPath = $userFoldersPath + $userFolder
        Move-Item $userFullPath $userOld -ErrorAction SilentlyContinue
    }

}

You need to do 2 things before running this.

First of all do a text file with the users folder you want to move.

userfolders.txt

frwa8233

tret4322

trwe4468

And then make a folder where you want to archive this user folders.

In my case It will be in c:\scripts\old.

When that is done, we just need to call the function with

first the text file path and second with the path to the folder where all of the user folders are

and third we need the path to the archive folder.

Move-UserFolders 'c:\scripts\userfolders.txt' 'c:\katalog01\' 'c:\scripts\old'
 
Technorati Tags: ,

Related posts:

  1. Deployment Share Sorter
  2. Create Lab AD Functions (Updated)
  3. Clean-Temp function
  4. Ping-Status function
  5. Function killNotes


Comments
MSFT Scripting Guys WordPress v1.1.3 December 17th, 2009 (4:41 pm)
comment

RT @walle75: The function are updated with source folder, http://bit.ly/7cJZrO <=good update

Fredrik Wall WordPress v1.1.3 December 17th, 2009 (4:48 pm)
comment

Function of the day, Move-UserFolders, #PowerShell #Functions http://bit.ly/7cJZrO

MSFT Scripting Guys WordPress v1.1.3 December 17th, 2009 (4:50 pm)
comment

RT @walle75: Function of the day, Move-UserFolders, #PowerShell #Functions http://bit.ly/7cJZrO <=cool

Fredrik Wall WordPress v1.1.3 December 17th, 2009 (5:15 pm)
comment

The function are updated with source folder, http://bit.ly/7cJZrO

Add Comment

Name (Required)

E-mail (Required)

Website

Comment (Required)