Cleaned up

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

View File

@@ -1,25 +1,25 @@
#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 {
Try {
$profiles = Get-CimInstance -Class Win32_UserProfile
} Catch {
} Catch {
Write-Warning "Failed to retreive user profiles on $ComputerName"
Exit
}
}
ForEach ($profile in $profiles) {
ForEach ($profile in $profiles) {
$sid = New-Object System.Security.Principal.SecurityIdentifier($profile.SID)
$account = $sid.Translate([System.Security.Principal.NTAccount])
$accountDomain = $account.value.split("\")[0]
@@ -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
@@ -102,10 +100,8 @@ ForEach ($computer in $ComputerName)
} Catch {
Write-Host "Error during delete the profile" -ForegroundColor Red
}
}
}
If($profilesFound -eq 0){
Write-Warning "No profiles to delete"
}
}
If($profilesFound -eq 0){
Write-Warning "No profiles to delete"
}