From 20f22ba7f366bf6acb6e6f3ebe10b15778a56411 Mon Sep 17 00:00:00 2001 From: poslop Date: Thu, 13 Feb 2025 12:01:37 -0600 Subject: [PATCH] testing new script --- scripts/DeleteOldProfilesManual.ps1 | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/scripts/DeleteOldProfilesManual.ps1 b/scripts/DeleteOldProfilesManual.ps1 index 38cb835..5305067 100644 --- a/scripts/DeleteOldProfilesManual.ps1 +++ b/scripts/DeleteOldProfilesManual.ps1 @@ -28,6 +28,10 @@ ForEach ($computer in $ComputerName) $loaded = $profile.Loaded $lastUseTime = $profile.LastUseTime $isExcluded = $False + $special = $profile.Special + + + If ($special) {continue} #Calculation of the login date $lastLoginDate = $null @@ -54,15 +58,26 @@ ForEach ($computer in $ComputerName) } } - If($isExcluded) {continue} + If($isExcluded) {Write-Host "Profile $accountName was excluded!" continue} - If($InactiveDays -ne [uint32]::MaxValue -And $profileUnusedDays -le $InactiveDays){continue} + If($InactiveDays -ne [uint32]::MaxValue -And $profileUnusedDays -le $InactiveDays){ + + Write-Host "Skipping ""$account"" as it is recently used." -ForegroundColor Blue + Write-Host "Account SID: $sid" + Write-Host "Special system service user: $special" + Write-Host "Profile Path: $profilePath" + Write-Host "Loaded : $loaded" + Write-Host "Last use time: $lastUseTime" + If ($lastLoginDate -ne $null) { Write-Host "Last login: $lastLoginDate" } + Write-Host "Profile unused days: $profileUnusedDays" + continue} $profilesFound ++ If ($profilesFound -gt 1) {Write-Host "`n"} - Write-Host "Start deleting profile ""$account"" on computer ""$computer"" ..." -ForegroundColor Green + Write-Host "Start deleting profile ""$account"" on computer ""$computer"" ..." -ForegroundColor Red Write-Host "Account SID: $sid" + Write-Host "Special system service user: $special" Write-Host "Profile Path: $profilePath" Write-Host "Loaded : $loaded" Write-Host "Last use time: $lastUseTime" @@ -84,6 +99,6 @@ ForEach ($computer in $ComputerName) } If($profilesFound -eq 0){ - Write-Warning "No profiles found on $ComputerName with Name $UserName" + Write-Warning "No profiles to delete" } }