From cfe2b62100a827f94b9bf6d8f61eb17a894382c3 Mon Sep 17 00:00:00 2001 From: Jaap Brasser Date: Sun, 10 May 2020 17:47:20 +0200 Subject: [PATCH 1/3] =?UTF-8?q?Updated=20Get-OrphanHomeFolder=20for=20issu?= =?UTF-8?q?e=2037=20=F0=9F=93=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Get-OrphanHomeFolder/Get-OrphanHomeFolder.ps1 | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/Get-OrphanHomeFolder/Get-OrphanHomeFolder.ps1 b/Get-OrphanHomeFolder/Get-OrphanHomeFolder.ps1 index d538fdc..3aaca4d 100644 --- a/Get-OrphanHomeFolder/Get-OrphanHomeFolder.ps1 +++ b/Get-OrphanHomeFolder/Get-OrphanHomeFolder.ps1 @@ -35,17 +35,20 @@ Setting this switch parameter will handle the strings in the ExcludePath paramet .PARAMETER CheckHomeDirectory Setting this switch parameter will check the full path of the folder against the HomeDirectory attribute of an ADObject, when using this switch make sure that the correct shared folder or DFS path is used, otherwise output can be unreliable +.PARAMETER LastLogonDate +Switch parameter that will look at the most recent file change in the root folder and report this back + .NOTES Name: Get-OrphanHomeFolder.ps1 Author: Jaap Brasser -Version: 1.9 +Version: 2.0 DateCreated: 2012-10-19 -DateUpdated: 2015-09-23 +DateUpdated: 2020-05-10 Blog: http://www.jaapbrasser.com .LINK http://www.jaapbrasser.com - + .EXAMPLE .\Get-OrphanHomeFolder.ps1 -HomeFolderPath \\Server01\Home -FolderSize @@ -111,7 +114,8 @@ param( [switch]$DisplayAll, [switch]$UseRobocopy, [switch]$RegExExclude, - [switch]$CheckHomeDirectory + [switch]$CheckHomeDirectory, + [switch]$LastLogonDate ) # Check if HomeFolderPath is found, exit with warning message if path is incorrect if (!(Test-Path -LiteralPath $HomeFolderPath)){ @@ -172,6 +176,11 @@ $ListOfFolders | ForEach-Object { Measure-Object -Property Length -Sum -ErrorAction SilentlyContinue | Select-Object -Exp Sum) $HashProps.SizeinMegaBytes = "{0:n2}" -f ($HashProps.SizeinBytes/1MB) } + + if ($LastLogonDate) { + $HashProps.LastLogonDate = Get-ChildItem -LiteralPath $_.Fullname -Force -ErrorAction SilentlyContinue | + Where-Object {-not $_.PSISContainer} | Sort-Object -Property LastWriteTime | Select-Object -Last 1 -ExpandProperty LastWriteTime + } if ($MoveFolderPath) { $HashProps.DestinationFullPath = Join-Path -Path $MoveFolderPath -ChildPath (Split-Path -Path $_.FullName -Leaf) @@ -182,6 +191,8 @@ $ListOfFolders | ForEach-Object { } } + if () + # Output the object New-Object -TypeName PSCustomObject -Property $HashProps @@ -197,6 +208,11 @@ $ListOfFolders | ForEach-Object { $HashProps.SizeinMegaBytes = "{0:n2}" -f ($HashProps.SizeinBytes/1MB) } + if ($LastLogonDate) { + $HashProps.LastLogonDate = Get-ChildItem -LiteralPath $_.Fullname -Force -ErrorAction SilentlyContinue | + Where-Object {-not $_.PSISContainer} | Sort-Object -Property LastWriteTime | Select-Object -Last 1 -ExpandProperty LastWriteTime + } + if ($MoveFolderPath -and $MoveDisabled) { $HashProps.DestinationFullPath = Join-Path -Path $MoveFolderPath -ChildPath (Split-Path -Path $_.FullName -Leaf) Move-Item -LiteralPath $HashProps.FullPath -Destination $HashProps.DestinationFullPath -Force @@ -217,6 +233,11 @@ $ListOfFolders | ForEach-Object { $HashProps.SizeinMegaBytes = "{0:n2}" -f ($HashProps.SizeinBytes/1MB) } + if ($LastLogonDate) { + $HashProps.LastLogonDate = Get-ChildItem -LiteralPath $_.Fullname -Force -ErrorAction SilentlyContinue | + Where-Object {-not $_.PSISContainer} | Sort-Object -Property LastWriteTime | Select-Object -Last 1 -ExpandProperty LastWriteTime + } + # Output the object New-Object -TypeName PSCustomObject -Property $HashProps } From 84fbd3a7228a42591680adfaff6db30174d1f191 Mon Sep 17 00:00:00 2001 From: Jaap Brasser Date: Sun, 10 May 2020 20:42:49 +0200 Subject: [PATCH 2/3] =?UTF-8?q?Fixed=20bug=20=F0=9F=90=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Get-OrphanHomeFolder/Get-OrphanHomeFolder.ps1 | 2 -- 1 file changed, 2 deletions(-) diff --git a/Get-OrphanHomeFolder/Get-OrphanHomeFolder.ps1 b/Get-OrphanHomeFolder/Get-OrphanHomeFolder.ps1 index 3aaca4d..458fb29 100644 --- a/Get-OrphanHomeFolder/Get-OrphanHomeFolder.ps1 +++ b/Get-OrphanHomeFolder/Get-OrphanHomeFolder.ps1 @@ -191,8 +191,6 @@ $ListOfFolders | ForEach-Object { } } - if () - # Output the object New-Object -TypeName PSCustomObject -Property $HashProps From 079ba53a950b76a928f952736268ca62f9acc462 Mon Sep 17 00:00:00 2001 From: Jaap Brasser Date: Mon, 11 May 2020 09:20:04 +0200 Subject: [PATCH 3/3] =?UTF-8?q?Changed=20error=20property=20to=20message?= =?UTF-8?q?=20property=20=F0=9F=93=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Get-OrphanHomeFolder/Get-OrphanHomeFolder.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Get-OrphanHomeFolder/Get-OrphanHomeFolder.ps1 b/Get-OrphanHomeFolder/Get-OrphanHomeFolder.ps1 index 458fb29..dee5e39 100644 --- a/Get-OrphanHomeFolder/Get-OrphanHomeFolder.ps1 +++ b/Get-OrphanHomeFolder/Get-OrphanHomeFolder.ps1 @@ -168,7 +168,7 @@ $ListOfFolders | ForEach-Object { # If no matching samaccountname is found this code is executed and displayed if (!($ADResult)) { $HashProps = @{ - 'Error' = 'Account does not exist and has a home folder' + 'Message' = 'Account does not exist and has a home folder' 'FullPath' = $_.FullName } if ($FolderSize) { @@ -197,7 +197,7 @@ $ListOfFolders | ForEach-Object { # If samaccountname is found but the account is disabled this information is displayed } elseif (([boolean]((-join $ADResult.Properties.useraccountcontrol) -band 2))) { $HashProps = @{ - 'Error' = 'Account is disabled and has a home folder' + 'Message' = 'Account is disabled and has a home folder' 'FullPath' = $_.FullName } if ($FolderSize) { @@ -222,7 +222,7 @@ $ListOfFolders | ForEach-Object { # Folders that do have active user accounts are displayed if -DisplayAll switch is set } elseif ($ADResult -and $DisplayAll) { $HashProps = @{ - 'Error' = $null + 'Message' = 'Account is active' 'FullPath' = $_.FullName } if ($FolderSize) {