Move all homedirectory folders to a new location

TJ Cooper 26 Reputation points
2020-08-04T23:05:29.56+00:00

I want to move the homedirectory folder for all users in an OU to a new share. I have this:

$users = get-aduser -Filter * -SearchBase "OU=HDrive_Delete,OU=SC,OU=Disabled Accounts,DC=test,DC=LOC" -Properties SamAccountName,homedirectory,Division

foreach($user in $users)
{
Move-Item "($_.homedirectory)" \\fileserver\DisabledHomeDrives\$_.homedirectory
} 

It not working. Should I create two strings, sourcefolder, targetfodler, and then pass that to a robocopy script?

I need to query an OU
Move the folder and append the folder name
Delete the original folder (in the case robocopy is used)

thank you!!!

Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,355 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. 2020-08-05T07:09:32.307+00:00

    What is the error message?Does the corresponding folder on the shared folder exist?

    0 comments No comments

  2. 2020-08-20T01:46:30.76+00:00

    Hi, given that this post has been quiet for a while, this is a quick question and answer. Has your question been solved? If so, please mark it as an answer so that users with the same question can find and get help.
    :)

    0 comments No comments