You've already forked SharedScripts
mirror of
https://github.com/jaapbrasser/SharedScripts.git
synced 2025-12-24 21:51:38 +02:00
Updated Get-OrphanHomeFolder for issue 37 📰
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user