Загрузка данных
$UserName = 'a.askarov' # <-- логин пользователя
$Sid = ([Security.Principal.NTAccount]"allur\$UserName").Translate(
[Security.Principal.SecurityIdentifier]).Value
"SID: $Sid"
Get-WinEvent -FilterHashtable @{
LogName = 'Application'; ProviderName = 'Microsoft-Windows-User Profiles Service'
StartTime = (Get-Date).AddDays(-1)
} -ErrorAction SilentlyContinue |
Where-Object { $_.Level -in 1,2,3 } |
Select-Object -First 10 TimeCreated, Id, Message | Format-List
-------------------------------------------------------------------------------------------------
Если ошибки 1542 и/или 1508 с упоминанием UsrClass.dat
-------------------------------------------------------------------------------------------------
$ErrorActionPreference = 'Stop'
$UserName = 'a.askarov' # <-- логин пользователя
$Domain = 'allur'
$Sid = ([Security.Principal.NTAccount]"$Domain\$UserName").Translate(
[Security.Principal.SecurityIdentifier]).Value
$Base = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList'
$Key = "$Base\$Sid"
$BakKey = "$Base\$Sid.bak"
$Backup = "C:\ProfileRepair-$UserName-$(Get-Date -Format 'yyyyMMdd-HHmmss')"
function Invoke-Native([string]$Exe, [string[]]$Arguments) {
$old = $ErrorActionPreference; $ErrorActionPreference = 'Continue'
$null = & $Exe @Arguments 2>&1; $c = $LASTEXITCODE
$ErrorActionPreference = $old; return $c
}
# --- Проверки ---
foreach ($h in @($Sid, "${Sid}_Classes")) {
if (Test-Path "Registry::HKEY_USERS\$h") {
throw 'Профиль загружен. Пользователь должен выйти из системы (или перезагрузите ПК).'
}
}
$HasKey = Test-Path $Key
$HasBak = Test-Path $BakKey
if (-not ($HasKey -or $HasBak)) { throw 'Записи профиля нет. Передать администратору.' }
$SrcKey = if ($HasBak) { $BakKey } else { $Key }
$ProfilePath = (Get-ItemProperty $SrcKey).ProfileImagePath
if ($ProfilePath -like '*\TEMP*') { throw "Запись указывает на TEMP ($ProfilePath). Передать администратору." }
if (-not (Test-Path $ProfilePath)) { throw "Папка профиля не найдена: $ProfilePath" }
"Профиль: $ProfilePath"
# --- Резервная копия реестра ---
New-Item -ItemType Directory -Path $Backup | Out-Null
Invoke-Native reg.exe @('export',
'HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList',
"$Backup\ProfileList.reg", '/y') | Out-Null
# --- Перенос UsrClass.dat и служебных файлов ---
$Dir = "$ProfilePath\AppData\Local\Microsoft\Windows"
Get-ChildItem -LiteralPath $Dir -Force -File |
Where-Object { $_.Name -like 'UsrClass.dat*' } |
ForEach-Object {
Invoke-Native takeown.exe @('/F', $_.FullName, '/A') | Out-Null
Invoke-Native icacls.exe @($_.FullName, '/grant', '*S-1-5-32-544:(F)') | Out-Null
Move-Item -LiteralPath $_.FullName -Destination $Backup -Force
"Перенесён: $($_.Name)"
}
# --- Восстановление записи профиля ---
if ($HasKey -and $HasBak) {
# Лишняя запись, созданная при входе в TEMP, — убираем в сторону
Rename-Item -LiteralPath $Key -NewName "$Sid.old-$(Get-Date -Format 'HHmmss')"
}
if ($HasBak) { Rename-Item -LiteralPath $BakKey -NewName $Sid }
New-ItemProperty -LiteralPath $Key -Name State -PropertyType DWord -Value 0 -Force | Out-Null
New-ItemProperty -LiteralPath $Key -Name RefCount -PropertyType DWord -Value 0 -Force | Out-Null
Get-ItemProperty $Key | Select-Object ProfileImagePath, State, RefCount | Format-List
Write-Host "Готово. Резервная копия: $Backup. Перезагрузите ПК." -ForegroundColor Green
-------------------------------------------------------------------------------------------------