From cfe2b62100a827f94b9bf6d8f61eb17a894382c3 Mon Sep 17 00:00:00 2001 From: Jaap Brasser Date: Sun, 10 May 2020 17:47:20 +0200 Subject: [PATCH] =?UTF-8?q?Updated=20Get-OrphanHomeFolder=20for=20issue=20?= =?UTF-8?q?37=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 }