Delete DeleteOldProfiles.ps1
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
$daysInactive = 14 # Specify the number of days of inactivity
|
||||
$inactiveDate = (Get-Date).AddDays(-$daysInactive)
|
||||
$homeDirectoryPath = "C:\Users" # Path to user home directories
|
||||
|
||||
# Get all user profiles
|
||||
Get-WmiObject Win32_UserProfile | ForEach-Object {
|
||||
$profile = $_
|
||||
$userFolder = $profile.LocalPath
|
||||
|
||||
# Check if the profile folder exists and get the last modification date
|
||||
if (Test-Path $userFolder) {
|
||||
$lastWriteTime = (Get-Item $userFolder).LastWriteTime
|
||||
|
||||
if ($lastWriteTime -lt $inactiveDate) {
|
||||
Write-Host "Deleting user profile: $($profile.LocalPath) Last Modified: $lastWriteTime" -ForegroundColor Red
|
||||
|
||||
# Remove the user profile
|
||||
$profile.Delete()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user