Jump to content

Recommended Posts

Posted

Hi folks,

 

I'm no scripting guru so please bear with me on this.

 

I have an urgent need to relocate users home directories from one location to another.

 

Currently our \\UNCPath\user shared folders\ area contains both pupils and staff folders which is a nono and isn't the best practice. I need to move all the pupils home folders to a new location \\UNCPath\pupils\

 

I've generated a username_year_group_x.csv file containing a single column samaccountname for all users from each year group and I want to feed it into a script and use those usernames to move the corresponding folders to their new location.

 

I know how to change the home folders from AD for all users but I just can't figure how to move the actual data!

 

Hope someone can help me!

Posted

I just modified my user script to move home directories if their year group changes for some reason. don’t know what language you plan to use, I used PowerShell.

If you just want to use the csv file you can use the import-csv command and the move-item command.

If you want to moved based on OU get quest active directory cmdlets and use the set-qaduser and get-qaduser commands.

This is not exact syntax so don’t copy and paste, I can look at details when I get in tomorrow if you need them.

$users = Get-qaduser –seachscope domain/ou
Foreach ($user in $users){
$home  = $user.homepath
$newhome = \\server\students\yeargroup\$user.samaccountname

Move-item –path $home –destination  $newhome
Set-qaduser –identify $user –homepath $newhome
}

 

That’s off the top of my head with no syntax checking etc., but should give you a good start.

Good luck

Posted

Thanks Dana for your reply. Yes, I think I prefer powershell at this point. I tried doing a script around robocopy and richcopy but got nowhere.

 

So my script is this, which may have a silly error in it as I wrote it at 2:30am.

 

 

$listPath = "d:\temp\csvs\test.csv"
$oldhome = "D:\DFSRoots\Public\User Shared Folders\"
$newhome = "D:\DFSRoots\Public\Users\Senior School\Pupils\test1\"
$list = import-csv $listPath
foreach($user in $list)
{
    $path = Join-Path $oldhome -childpath $user.username
    move-item $path $newhome
}

 

I get this error:

Move-Item : The process cannot access the file because it is being used by another process.

At C:\Users\administrator.EA\Desktop\move_home_folders.ps1:8 char:15

+ move-item <<<< $path $newhome

+ CategoryInfo : WriteError: (D:\DFSRoots\Public\User Shared Folders\: DirectoryInfo) [Move-Item], IOExcep

tion

+ FullyQualifiedErrorId : MoveDirectoryItemIOError,Microsoft.PowerShell.Commands.MoveItemCommand

Posted
Move-Item : The process cannot access the file because it is being used by another process.

 

Pretty much as it says :( Either "someone" or "something" has the files/directory open.

 

Could be back-up scripts, logged on users etc etc etc. If you're moving it you'll need to kick everyone out of it.

 

Steve

Posted

Steve, not sure if there was anyone else attached to the server at 2:30am!!! However, I think DFSR might be the culprit here.

 

If DFSR is the problem then I'll need to stop it before I perform the copy - which will create on heckuva a backlog!!!

 

Thoughts?

Posted
Steve, not sure if there was anyone else attached to the server at 2:30am!!!

 

AV clients running? Backup software? Any service accounts? Locked open files? Could be a lot of things :)

 

You should be able to check what's got a file open (If you find a specific file it's failing on) in the File manager thingy within the server

 

Steve

Posted

The script looks OK to me, I was able to run it on my machine just changing the paths and it worked.

I have two suggestions

For your access error either reboot the server or go into the share session manager and kick everyone out. This will ensure no open files. Also check that your user has permission to the directories and all sub directories. I assume you’re using and admin account so this shouldn’t be the case, but never hurts to check.

You will want to change the path in AD so they connect to the new share. If you do this outside of your script, what you have is fine.

If you want to do it with in the script use UNC paths when moving their files so you can use the same newpath variable it the set-qaduser command.

 

Hope this helps,

Let us know if you get it working properly.

  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...