So in a thread on Microsoft Social. A user asked for help moving users to a directory after they had logged on to a Windows 7 workstation. This is my suggestion.
So first lets create a list of who has logged on to the new platform. A simple script that saves a file with the name of the logged in user in a folder. We will then execute this using Task Scheduler on logon or logon script of the user. Remember to grant rights for all users to create files in that share.
$LoggedOnUserFolder = '\\server\share$'
$UserFile = $LoggedOnUserFolder+'\'+$env:username
if ((Test-Path $UserFile) -eq $False)
{
New-Item -Type File $UserFile |Out-Null
}So now we have a share with files of all users that has logged on. Lets do something with them.
#where should all the users be?
$NewUserPath = 'OU=Organizational Unit,DC=example,DC=com'
#Where are the files from the clients?
$LoggedOnUserFolder = '\\server\share$'
#Do a simple array of usernames
$Usernames = Get-ChildItem $LoggedOnUserFolder |Select-Object -ExpandProperty Name
#Get all users and move those that are on the list and moved.
Get-ADUser -Filter * | Where {$userNames -contains $_.samaccountname -and $_.DistinguishedName -notlike "*$NewUserPath"}| Move-ADObject -TargetPath $NewUserPathMake sure that the source path is correct. Otherwise you can trick the system to migrate other users. So after running the second script we have moved the users.. Yeay.