0 votes

Hi folks,

I already have a great script (thank you) that monitors our HR system for adds/removes/changes of our staff and reflects those changes in AD via scheduled task.

I would like to setup a Business Rule that monitors "AFTER CHANGING LOGON NAME OF USER", the home directory of that user will be 'renamed' to the new logon name.

eg.

username = jsmith home drive = \\server\users\jsmith

user gets married and changes name to jblack. Existing daily script will pick up this change in the HR system and will amend the account (name, display name, logon name etc etc). HERE is where the business rule will be invoked and will rename the existing home drive folder (jsmith) to jblack

result - username = jblack home drive = \\server\users\jblack

Or, is there a more efficient way of doing this? Could I possibly incorporate it into the existing script?

Thanks

Corey

by (170 points)

1 Answer

0 votes
by (216k points)
selected by
Best answer

Hello Corey,

The best way to achieve what you want is to create a Business Rule triggered after changing a username. To create such a Business Rule:

  1. Create a new Business Rule.

  2. On the 2nd step of the Create Business Rule wizard, select User and After Updating a User.

  3. On the 3rd step, add the Run a program or PowerShell script action and paste the following script that renames a user's home folder:

     $homeDirectoryPath = "%homeDirectory%"
    
     # Check whether the home directory exists
     if(!(Test-Path -Path $homeDirectoryPath))
     {
         $Context.LogMessage("The home directory path is invalid", "Warning")
         return
     }
    
     # Rename the home directory
     $homeDirectory = Get-Item -Path $homeDirectoryPath
     $newHomeDirectoryPath = $homeDirectory.Parent.FullName + "\%username%"
    
     $Context.TargetObject.MoveHomeDirectory($newHomeDirectoryPath, $NULL)
    
  4. Enter a short description for the script and click OK.

  5. Now, you need to configure when the home folder must be renamed. Right-click the action you've just added and click Add Condition.

  6. Select the If <property> changed condition type.

  7. Specify If User Logon Name (pre-Windows 2000) has changed.

  8. Click OK.

  9. Also, you need to run the script only if a user has a home folder. Right-click the action and click Add Condition again.

  10. Select the If <property> <relation> <value> condition type.

  11. Specify If Home Directory is not empty.

  12. Click OK and finish creation of the Business Rule.

0

Perfect as usual.

Thanks guys. Always a great help.

Related questions

0 votes
1 answer

I am using this script modified for my testing. Import-Module Adaxes $csvFilePath = "D:\TestFeed\ImportNewUsers.csv" # Path to pick up feed file $userIdColumn = "Employee Number" # TODO: ... initial. I would like to add a 2 for now if the sam isn't unique.

asked Oct 17, 2022 by mightycabal (1.0k points)
0 votes
1 answer

Hi We've had a request to forward to a mailbox any user who has had their username and email address changed, the email is to show old user name, new user name, old ... and email address, would it need to be a Powershell script for this? Thanks in advance.

asked Jan 23, 2015 by CBurn (700 points)
0 votes
1 answer

Hello We are using the built in Copy command to copy users but have run into an issue. We get the error 'can't create a home drive because it already exists'. No ... trying to create the original users home drive again. Is there any way round this? Thanks.

asked Mar 2, 2015 by CBurn (700 points)
0 votes
1 answer

Hello Adaxes Support, is there any way you could help me with a script that changes the permissions on a users home folder? I need to remove the permission to delete the folder and add the permission to delete subfolders and files.

asked Aug 1 by dominik.stawny (280 points)
0 votes
1 answer

Good Morning, I've been working through some of my processes and I'm not looking to make sure the deletion of Home directories (both remote and standard) as well as ... for user deletion. If there are any questions or clarification needed, please let me know.

asked Oct 16, 2015 by jtop (700 points)
3,548 questions
3,238 answers
8,232 comments
547,813 users