Function of the day – Move UserFolders

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: ,

No related posts.

This entry was posted in PowerShell Blogs and tagged , . Bookmark the permalink.

5 Responses to Function of the day – Move UserFolders

  1. Pingback: Fredrik Wall

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

  3. Fredrik Wall says:

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

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

  5. Fredrik Wall says:

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

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>