none
Moving home folder contents to another users folder from CSV RRS feed

  • Question

  • I am currently trying to automate the leavers process and am now stumped. I have a script that already does most of the changes and the final step needs to move the home folder to a delegated user.

    The CSV is user,Delegate,Office,description,Department,Telephonenumber

    All ideas welcome.

    • Moved by Bill_Stewart Wednesday, December 12, 2018 9:32 PM This is not "scripts on demand"
    Thursday, September 6, 2018 3:03 PM

All replies

  • What errors are you getting and what code are you using to attempt this?

    Are the user's home folder and the delegate user's home folder on the same machine/share?

    Thursday, September 6, 2018 3:11 PM
  • Both the delegate and leaver homedirectory's are on the same fileserver \\storage01\homedirectory\leaver  and \\storage01\homedirectory\Delegate

    I have only tried to export the details of the users to another csv then thought about using robocopy but I cant even get that to work. It does not show any errors, it just doesn't export correctly. It only lists one of the users.

    Import-module ActiveDirectory
    Import-Csv -Path C:\Leavers.csv | ForEach-Object {
    Get-ADUser $_.User -Properties HomeDirectory | Select-Object homedirectory | Export-CSV C:\homedirectory.csv
    }

    The leavers script for everything else is below and so far works fine.

    Import-module ActiveDirectory
    Import-CSV C:\Leavers.csv | % {
    Set-ADUser $_.User -office $_.office
    Set-ADUser $_.User -description $_.description
    Set-ADUser $_.User -Replace @{TelephoneNumber=$_.TelephoneNumber}
    Set-ADUser $_.User -Department $_.Department
    Disable-ADAccount $_.User
    }
    Import-CSV C:\Leavers.csv | % {
    $ADGroups = Get-ADPrincipalGroupMembership $_.User | where {$_.Name -ne "Domain Users"}
    Remove-ADPrincipalGroupMembership -ErrorAction SilentlyContinue $_.User -MemberOf $ADGroups -Confirm:$false
    }

    Import-CSV C:\Leavers.csv | % {
    Get-ADUser $_.User | Move-ADObject -targetpath "OU=Moved,OU=TestLeaversScript,OU=_Disabled Accounts,DC=Google,DC=Com"
    }



    Thursday, September 6, 2018 3:32 PM
  • in the leavers csv, do you have the full name or the username (samacccountname) in the "user" field?
    Thursday, September 6, 2018 3:40 PM
  • It has the username (samacccountname) in the "user" field
    Thursday, September 6, 2018 3:49 PM
  • Import-Csv -Path C:\Leavers.csv | ForEach-Object {
         Get-ADUser $_.User -Properties HomeDirectory | Select-Object -ExpandProperty homedirectory | Export-CSV C:\homedirectory.csv -Append
    }

    have you tried using the above? What do you actually get for the homedirectory data?


    Thursday, September 6, 2018 4:09 PM