Afternoon all, I have the following script that is designed to discover old AD accounts, filter the results to a certain user group (accounts starting 'P4'), export to CSV, forcefully give my security group ownership of the directories and then use RoboCopy to migrate the folders to a server share. RoboCopy is where I'm facing a silly issue I can't find a straight forward answer to. Not all the users have HomeDirectories in AD and so when RoboCopy comes across a null value, it takes places it into my command but unwittingly thinks it's the sourcedir. Here is the code: CODE --> PowerShell# Import AD into Quest CODE --> PowerShellimport-module activedirectory CODE --> PowerShell# Find the date 365 days ago as a variable CODE --> PowerShell$old_p45_profile_path = "\\server\folder\profiles" CODE --> PowerShell$old_p45_home_path = "\\server\folder\home" CODE --> PowerShell$StartDate = [DateTime]::Now.AddDays(-365) CODE --> PowerShell# Search for users that have not logged in for 365 days or more AND their account was created more than 365 days ago CODE --> PowerShellSearch-ADAccount -UsersOnly -AccountInactive -TimeSpan 365.00:00:00 | %{Get-QADUser $_.ObjectGuid -CreatedBefore $StartDate} | select samaccountname, name, whenCreated, lastLogonTimeStamp, profilePath, homeDirectory | where-object {$_.samaccountname -like "P4*"}| export-csv c:\output\inactiveusers.csv -NoTypeInformation CODE --> PowerShell# Read in List of Folders CODE --> PowerShell$rows=Import-Csv "inactiveusers.csv" CODE --> PowerShellforeach ($row in $rows) CODE --> PowerShell$profilePath = $row.ProfilePath CODE --> PowerShelltakeown /F $profilePath /R /A CODE --> PowerShellforeach ($row in $rows) CODE --> PowerShell$homeDirectory = $row.HomeDirectory CODE --> PowerShelltakeown /F $homeDirectory /R /A CODE --> PowerShell# Move Profiles CODE --> PowerShellforeach ($row in $rows) { CODE --> PowerShellif ($profilePath -EQ $NULL) {} CODE --> PowerShellelse {robocopy $profilePath $old_p45_profile_path /MIR /MOVE /EFSRAW CODE --> PowerShell# Move Home Directories CODE --> PowerShellforeach ($row in $rows) { CODE --> PowerShellif ($homeDirectory -EQ $NULL) {} CODE --> PowerShellelse {robocopy $homeDirectory $old_p45_home_path /MIR /MOVE /EFSRAW } How do I get RoboCopy to ignore a null cell in the CSV and move to the next cell? Cheers! |
|