Rename home folders for disabled Active Directory users with Orchestrator

This Orchestrator Runbooks displays an example on how to rename home folders for every disabled user in Active Directory. Every disabled user home folder will be renamed to “foldername_<todays date>” by these Runbooks.

The Runbooks will log to a text file but the recommendation is to log to a database instead if logging is needed.

To get the Runbooks working you will need to have the Active Directory PowerShell module installed on the Runbook server. The alternative way, and probably better, is to execute the PowerShell command on a remote server that have the Active Directory PowerShell module.

The Runbook also assumes that the home folder structure is very simple with the home folders named after the users SamAccountName (Ex: \\fileserver\home$\jonand).

To test this Runbooks you will need to change the “Variables” activity and the credentials in the activity “Map Homfolder Path” at the Runbook “1.2 Rename Folders”. You will also need to create a “c:\tmp” directory for the logs.

Runbook to find all disabled users in Active Directory

 Rename home folders for disabled Active Directory users1

Explanation of Runbook activities

Activity – Disabled Users
Import-Module ActiveDirectory
$DisabledUsers = Search-ADAccount -AccountDisabled
 
Activity – Get SamAccountName
$DistinguishedName = “{DisabledUsers from “Disable“{DisabledUsers from “d Users”}”
$DistinguishedNameSplitOne = $DistinguishedName.Split(“=”)
$DistinguishedNameSplitTwo = $DistinguishedNameSplitOne[1].Split(“,”)
$SamAccountName = $DistinguishedNameSplitTwo[0]

Rename home folders

  Rename home folders for disabled Active Directory users2

Explanation of Runbook activities

Activity – Check if Mapped Drive
$FolderExist = Test-Path -Path “{HomeFolderPath from “Variables”}”

Activity – Check if Folder Exist
$FolderExist = Test-Path -Path “{HomeFolderPath from “Variables”}\{HomeFolderName from “Initialize Data”}”

Activity – Rename Folder
Rename-Item “{HomeFolderPath from “Variables”}\{HomeFolderName from “Initialize Data”} {HomeFolderPath from “Variables”}\{HomeFolderName from “Initialize Data”}_{Format Result from “Format Date/Time”}”

Activity – Check if Rename Folder was Successful
$FolderExist = Test-Path -Path “{HomeFolderPath from “Variables”}\{HomeFolderName from “Initialize Data”}_{Format Result from “Format Date/Time”}”

Download Runbook: RenameHomeFoldersForDisabledUsers

No comments yet.

Leave a Reply