Not
Bu sayfaya erişim yetkilendirme gerektiriyor. Oturum açmayı veya dizinleri değiştirmeyi deneyebilirsiniz.
Bu sayfaya erişim yetkilendirme gerektiriyor. Dizinleri değiştirmeyi deneyebilirsiniz.
Bu makalede sağlanan örnek betik, kayıt defterinden ve C:\users klasöründen yalnız bırakılmış profil bilgilerini temizlemeye yardımcı olabilir.
Profiller eksik veya hatalı bir şekilde kaldırılırsa, ek kullanıcı klasörleri oluşturulabilir veya kullanıcılar oturum açtıktan sonra TEMP profilleri alabilir. Bazı durumlarda, bu profiller henüz oturum açmamış olsa bile TEMP profillerinin kullanıldığı bir durumda birçok profil olabilir.
Şunlar için geçerlidir: Windows 10, Windows 11, Windows Server 2016 ve sonraki sürümler
Önemli
Bu örnek betik, herhangi bir Microsoft standart destek programı veya hizmeti altında desteklenmez.
Örnek betik, herhangi bir garanti olmadan OLDUĞU GIBI sağlanır. Microsoft, satılabilirlik veya belirli bir amaca uygunlukla ilgili zımni garantiler dahil ancak bunlarla sınırlı olmaksızın tüm zımni garantileri reddeder.
Örnek betiklerin ve belgelerin kullanımından veya performansından kaynaklanan tüm riskler sizinle birlikte kalır. Hiçbir durumda Microsoft, yazarları veya betiklerin oluşturulması, üretimi veya teslimi ile ilgili herhangi bir kişi, örnek betiklerin veya belgelerin kullanımından veya kullanılamama durumundan kaynaklanan herhangi bir zarardan (bunlarla sınırlı olmaksızın, iş kârı kaybı, iş kesintisi, iş bilgisi kaybı veya diğer maddi kayıplar dahil) sorumlu tutulamaz, Microsoft'a bu tür hasarlar olabileceği bildirilmiş olsa bile.
#
# usage:
# PowerShell /file OrhanedProfile.ps1 [-clean]
#
# The clean switch enables the deletion to take place. Otherwise, it reports what it could do.
#
Param(
[switch]$bClean = $false
)
# Check if running as an Administrator
if( -NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator") )
{
Write-Host "Please run as a member of the Administrators group"
break
}
# Get Profiles folder
$ProfilesListRegPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
$ProfilesFolder = $null
$ProfilesFolder = Get-ItemPropertyValue -Path $ProfilesListRegPath -Name "ProfilesDirectory"
If( $ProfilesFolder -eq $null )
{
Write-Host "Error getting the base profile folder."
break
}
"Profile folder: $ProfilesFolder"
#######################################
# Begin to get and check ProfileList key information
"Collecting ProfileList key information..."
"=" * 40
$WellKnownProfiles = @("S-1-5-18","S-1-5-19","S-1-5-20")
$ProfileListCount = 0
$ProfileListWarnCount = 0
$ProfileListInfo = @{}
Get-ChildItem -Path $ProfilesListRegPath -Exclude $WellKnownProfiles | ForEach-Object `
{
$ProfileSID = $_.PSChildName
$ProfilePath = $null
$ProfilePath = Get-ItemPropertyValue -Path $_.PSPath -Name "ProfileImagePath"
if( $ProfilePath -eq $null )
{
"Unable to read ProfileImagePath from ProfileList entry: $($_.Name)"
}
else
{
$ProfileListCount++
if( $ProfileSID -like "*.bak" )
{
"WARNING: .BAK ProfileList entry exists: $ProfileSID"
$ProfileListWarnCount++
}
try{
$ProfileListInfo.Add( $ProfilePath, $ProfileSID)
}
catch
{
$ProfileListInfo[ $ProfilePath ] = $ProfileListInfo[ $ProfilePath ] + ";$ProfileSID"
"WARNING: Multiple profile entries reference '$ProfilePath': $($ProfileListInfo[$ProfilePath])"
$ProfileListWarnCount++
}
}
}
"ProfileList Count...: $ProfileListCount"
"ProfileList Warnings: $ProfileListWarnCount"
#######################################
# Check for Orphaned ProfileListEntries - entries that reference deleted profile folders
""
"Looking for orphaned ProfileListEntries"
"=" * 40
$OrphanedProfileEntries = 0
$ProfileListInfo.GetEnumerator() | ForEach-Object `
{
$bOrphaned = $false
if( -not (Test-Path -Path $_.Key ) )
{
"Entry: $($_.Value) => $($_.Name)"
$OrphanedProfileEntries++
$bOrphaned = $true
}
elseif( -not (Get-ChildItem -Path $_.Key -include ntuser.dat,ntuser.man -Name -Force -File) )
{
"MISSING NTUSER.DAT or NTUSER.MAN: $($_.Value) => $($_.Name)"
$OrphanedProfileEntries++
$bOrphaned = $true
}
if( $bOrphaned -and $bClean )
{
$_.Value.Split( ";") | ForEach-Object `
{
try
{
$WMIUserProfile = gwmi -Class Win32_UserProfile -Filter "sid = '$($_)'"
$WMIUserProfile.Delete()
"Successfully deleted orphaned profile information."
}
catch
{
"Error occurred deleting profile. It may have only been partially deleted. [$($_.Exception.Message)]"
}
}
}
}
"=" * 40
"Orphaned ProfileListEntries: $OrphanedProfileEntries"
#######################################
# Check for Orphaned ProfileGUID entries - having SidString that reference deleted SID keys under ProfileList
# ProfileGUID would only exist on machines that have been domain joined at some time
$ProfileGUIDPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileGUID"
if( Test-Path -Path $ProfileGUIDPath )
{
""
"Looking for orphaned ProfileGUID entries"
"=" * 40
$OrphanedGUIDCount = 0
Get-ChildItem -Path $ProfileGUIDPath | ForEach-Object `
{
$SidString = $null
$SidString = Get-ItemPropertyValue -Path ($ProfilesListRegPath + "\" + $_.PSChildName) -Name "SidString" -ErrorAction SilentlyContinue
if( -not $SidString -eq $null )
{
if( $null -eq (Get-Item ($ProfilesListRegPath + "\" + $SidString) -ErrorAction SilentlyContinue) )
{
"Orphaned GUID: $($_.PSChildName)"
$OrphanedGUIDCount++
if( $bClean )
{
Remove-Item -Path $_.PSPath -Recurse -Force
}
}
}
}
"=" * 40
"Orphaned ProfileGUIDS: $OrphanedGUIDCount"
}
#######################################
# Check for Orphaned user folders - folders in the profile folder that are not referenced by ProfileList\SID keys
""
"Looking for orphaned user folders"
"=" * 40
$KnownUserFolders = @("All Users", "Default", "Default User", "LocalService", "NetworkService", "Public")
$OrhanedUserFolders = 0
Get-ChildItem -Path $ProfilesFolder -Exclude $KnownUserFolders -Directory -Force | ForEach-Object `
{
if( -not $ProfileListInfo.Contains( $_.FullName ) )
{
"Folder: $($_.FullName) (Created: $($_.CreationTime) - Modified $($_.LastWriteTime))"
$OrhanedUserFolders++
if( $bClean )
{
Remove-Item -Path ("\\?\$($_.FullName)") -Force -Recurse
}
}
}
"=" * 40
"Orphaned user folders: $OrhanedUserFolders"
""
"Completed."