Cleaned up

This commit is contained in:
poslop
2025-02-13 12:36:43 -06:00
parent 05f8c11367
commit 58d8f17f0e

View File

@@ -1,16 +1,16 @@
#Requires -RunAsAdministrator
[cmdletbinding(ConfirmImpact = 'High', SupportsShouldProcess=$True)]
$UserName = "*"
$ExcludedUserNames = @("Administrator", "Default Profile")
# CHANGE ME
# Change these settings
$ExcludedUserNames = @("Administrator", "Example Profile")
$InactiveDays = 14
$profilesFound = 0
$ComputerName = $env:computername
ForEach ($computer in $ComputerName)
{
$profilesFound = 0
Try {
$profiles = Get-CimInstance -Class Win32_UserProfile
} Catch {
@@ -35,8 +35,6 @@ ForEach ($computer in $ComputerName)
If ($special) {continue}
# Check if the account is Excluded or not
If($accountName.ToLower() -Eq $UserName.ToLower() -Or
($UserName.Contains("*") -And $accountName.ToLower() -Like $UserName.ToLower())) {
ForEach ($eun in $ExcludedUserNames) {
If($eun -ne [string]::Empty -And -Not $eun.Contains("*") -And ($accountName.ToLower() -eq $eun.ToLower())){
$isExcluded = $True
@@ -103,9 +101,7 @@ ForEach ($computer in $ComputerName)
Write-Host "Error during delete the profile" -ForegroundColor Red
}
}
}
If($profilesFound -eq 0){
Write-Warning "No profiles to delete"
}
}