Cleaned up
This commit is contained in:
@@ -1,25 +1,25 @@
|
|||||||
#Requires -RunAsAdministrator
|
#Requires -RunAsAdministrator
|
||||||
[cmdletbinding(ConfirmImpact = 'High', SupportsShouldProcess=$True)]
|
[cmdletbinding(ConfirmImpact = 'High', SupportsShouldProcess=$True)]
|
||||||
|
|
||||||
$UserName = "*"
|
# CHANGE ME
|
||||||
$ExcludedUserNames = @("Administrator", "Default Profile")
|
# Change these settings
|
||||||
|
|
||||||
|
$ExcludedUserNames = @("Administrator", "Example Profile")
|
||||||
$InactiveDays = 14
|
$InactiveDays = 14
|
||||||
|
|
||||||
|
|
||||||
|
$profilesFound = 0
|
||||||
$ComputerName = $env:computername
|
$ComputerName = $env:computername
|
||||||
|
|
||||||
|
Try {
|
||||||
|
|
||||||
ForEach ($computer in $ComputerName)
|
|
||||||
{
|
|
||||||
$profilesFound = 0
|
|
||||||
Try {
|
|
||||||
$profiles = Get-CimInstance -Class Win32_UserProfile
|
$profiles = Get-CimInstance -Class Win32_UserProfile
|
||||||
} Catch {
|
} Catch {
|
||||||
Write-Warning "Failed to retreive user profiles on $ComputerName"
|
Write-Warning "Failed to retreive user profiles on $ComputerName"
|
||||||
Exit
|
Exit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ForEach ($profile in $profiles) {
|
ForEach ($profile in $profiles) {
|
||||||
$sid = New-Object System.Security.Principal.SecurityIdentifier($profile.SID)
|
$sid = New-Object System.Security.Principal.SecurityIdentifier($profile.SID)
|
||||||
$account = $sid.Translate([System.Security.Principal.NTAccount])
|
$account = $sid.Translate([System.Security.Principal.NTAccount])
|
||||||
$accountDomain = $account.value.split("\")[0]
|
$accountDomain = $account.value.split("\")[0]
|
||||||
@@ -35,8 +35,6 @@ ForEach ($computer in $ComputerName)
|
|||||||
If ($special) {continue}
|
If ($special) {continue}
|
||||||
|
|
||||||
# Check if the account is Excluded or not
|
# 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) {
|
ForEach ($eun in $ExcludedUserNames) {
|
||||||
If($eun -ne [string]::Empty -And -Not $eun.Contains("*") -And ($accountName.ToLower() -eq $eun.ToLower())){
|
If($eun -ne [string]::Empty -And -Not $eun.Contains("*") -And ($accountName.ToLower() -eq $eun.ToLower())){
|
||||||
$isExcluded = $True
|
$isExcluded = $True
|
||||||
@@ -102,10 +100,8 @@ ForEach ($computer in $ComputerName)
|
|||||||
} Catch {
|
} Catch {
|
||||||
Write-Host "Error during delete the profile" -ForegroundColor Red
|
Write-Host "Error during delete the profile" -ForegroundColor Red
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
If($profilesFound -eq 0){
|
||||||
If($profilesFound -eq 0){
|
Write-Warning "No profiles to delete"
|
||||||
Write-Warning "No profiles to delete"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user