Powershel hatası
- Email Bot
- Kilobyte3

- Mesajlar: 400
- Kayıt: 20 Mar 2022, 23:50
- Teşekkür etti: 2 kez
- Teşekkür edildi: 35 kez
Powershel hatası
Selamlar powershell çalışmıyor. açılırken kapanıyor. powershell 7 yükledim ama hermes for windows çalıştıramadım. yardımcı olurmusunuz
- velociraptor
- Yottabyte4

- Mesajlar: 55014
- Kayıt: 14 Mar 2006, 02:33
- cinsiyet: Erkek
- Teşekkür etti: 21408 kez
- Teşekkür edildi: 12606 kez
Re: Powershel hatası
Başlat menüsünden PowerShell 7 veya pwsh uygulamasını açmayı dene. Pencere hemen kapanıyorsa, Win + R tuşlarına basıp şu komutu çalıştır :
pwsh -NoProfile
Bu şekilde açılıyorsa sorun büyük ihtimalle profil dosyasındadır. Profil dosyasını yeniden adlandırmak için aşağıdaki komutu çalıştır :
Rename-Item $PROFILE "$PROFILE.old" -ErrorAction SilentlyContinue
Ardından PowerShell’i tekrar aç. pwsh -NoProfile de kapanıyorsa PowerShell’i Ayarlar > Uygulamalar > Yüklü uygulamalar > PowerShell 7 > Kaldır yoluyla kaldırıp, yalnızca resmi Microsoft/GitHub kaynağından yeniden kurmayı dene. Hermes’in kurulum yönergesinde özellikle powershell.exe mi yoksa pwsh.exe mi istendiğini de kontrol et; PowerShell 7’nin çalıştırılabilir dosyası pwsh.exe’dir. Ayrıca PowerShell’i doğrudan kısayoldan değil, Komut İstemi açıp şu komutla başlatmak hata mesajını görmeyi sağlar :
pwsh
PowerShell’in açılır açılmaz kapanması bazen profil betiğinden, bazen bozuk kurulumdan, bazen de Hermes’in yanlış kabuk/parametreyle çalıştırılmasından kaynaklanır. PowerShell 7 kurmak, powershell.exe komutunu otomatik olarak PowerShell 7’ye dönüştürmez. (AI)
pwsh -NoProfile
Bu şekilde açılıyorsa sorun büyük ihtimalle profil dosyasındadır. Profil dosyasını yeniden adlandırmak için aşağıdaki komutu çalıştır :
Rename-Item $PROFILE "$PROFILE.old" -ErrorAction SilentlyContinue
Ardından PowerShell’i tekrar aç. pwsh -NoProfile de kapanıyorsa PowerShell’i Ayarlar > Uygulamalar > Yüklü uygulamalar > PowerShell 7 > Kaldır yoluyla kaldırıp, yalnızca resmi Microsoft/GitHub kaynağından yeniden kurmayı dene. Hermes’in kurulum yönergesinde özellikle powershell.exe mi yoksa pwsh.exe mi istendiğini de kontrol et; PowerShell 7’nin çalıştırılabilir dosyası pwsh.exe’dir. Ayrıca PowerShell’i doğrudan kısayoldan değil, Komut İstemi açıp şu komutla başlatmak hata mesajını görmeyi sağlar :
pwsh
PowerShell’in açılır açılmaz kapanması bazen profil betiğinden, bazen bozuk kurulumdan, bazen de Hermes’in yanlış kabuk/parametreyle çalıştırılmasından kaynaklanır. PowerShell 7 kurmak, powershell.exe komutunu otomatik olarak PowerShell 7’ye dönüştürmez. (AI)
- TRWE_2012
- Zettabyte1

- Mesajlar: 15695
- Kayıt: 25 Eyl 2013, 13:38
- cinsiyet: Erkek
- Teşekkür etti: 2755 kez
- Teşekkür edildi: 5695 kez
Re: Powershel hatası
Merhabalar.Email Bot yazdı: 02 Eyl 2026, 13:48 Selamlar powershell çalışmıyor. açılırken kapanıyor. powershell 7 yükledim ama hermes for windows çalıştıramadım. yardımcı olurmusunuz
Gerçi bizim Admin ne yapacağınızı anlatmış ama bende @Tarkan_Dost'un mesajına "betikleme yönünden" bir otomasyon ile cevap yazayım dedim ve aşağıda size özel bir .bat (.cmd) betiği tasarladım.
PowerShell_Diagnostic_Repair.TR.cmd (not : önce versiyon -0 ile kontrol et adım adım onaylayarak git.Eğer herşey yolunda giderse asıl betik versiyon-1 kullan...)
Versiyon -0
Kod: Tümünü seç
@echo off
chcp 65001 >nul
setlocal enabledelayedexpansion
set "DESKTOP=%USERPROFILE%\Desktop"
set "LOGFILE=%DESKTOP%\PowerShell_Tani_Raporu.txt"
echo PowerShell Tani ve Onarim Raporu > "%LOGFILE%"
echo Olusturulma: %DATE% %TIME% >> "%LOGFILE%"
echo. >> "%LOGFILE%"
echo ===================================================
echo PowerShell Tani ve Onarim Araci
echo ===================================================
echo.
echo Bu arac yalnizca bilgi okur ve Masaustune bir rapor yazar.
echo PowerShell 7 profil dosyanizi yalnizca 4. adimdaki soruda
echo acikca onay verirseniz yeniden adlandirir.
echo.
REM Adim 1 - PowerShell 7 (pwsh.exe) kurulu mu kontrol edilir
echo [1/5] PowerShell 7 (pwsh.exe) kontrol ediliyor...
where pwsh >nul 2>&1
if %ERRORLEVEL%==0 (
echo PowerShell 7 PATH icinde bulundu. >> "%LOGFILE%"
echo PowerShell 7 PATH icinde bulundu.
) else (
echo PowerShell 7 PATH icinde bulunamadi. >> "%LOGFILE%"
echo PowerShell 7 PATH icinde bulunamadi.
echo Kurulum adresi: https://github.com/PowerShell/PowerShell/releases
echo Kurulum adresi: https://github.com/PowerShell/PowerShell/releases >> "%LOGFILE%"
goto :RAPOR
)
REM Adim 2 - pwsh -NoProfile ile acilis testi
echo [2/5] "pwsh -NoProfile" acilisi test ediliyor...
pwsh -NoProfile -Command "exit 0"
if %ERRORLEVEL%==0 (
echo pwsh -NoProfile basariyla acildi. >> "%LOGFILE%"
echo pwsh -NoProfile basariyla acildi.
) else (
echo pwsh -NoProfile acilamadi. Kurulum bozuk olabilir. >> "%LOGFILE%"
echo pwsh -NoProfile acilamadi. Kurulum bozuk olabilir.
echo Oneri: PowerShell 7'yi Ayarlar'dan kaldirip resmi kaynaktan >> "%LOGFILE%"
echo yeniden kurun. >> "%LOGFILE%"
echo Oneri: PowerShell 7'yi resmi kaynaktan yeniden kurun.
goto :RAPOR
)
REM Adim 3 - Execution Policy kontrolu
echo [3/5] Execution Policy kontrol ediliyor...
for /f "delims=" %%P in ('pwsh -NoProfile -Command "Get-ExecutionPolicy"') do set "EXECPOLICY=%%P"
echo Mevcut execution policy: !EXECPOLICY! >> "%LOGFILE%"
echo Mevcut execution policy: !EXECPOLICY!
if /I "!EXECPOLICY!"=="Restricted" (
echo UYARI: Restricted politikasi profil betiklerinin calismasini engelleyebilir. >> "%LOGFILE%"
echo UYARI: Restricted politikasi profil betiklerinin calismasini engelleyebilir.
)
REM Adim 4 - profil dosyasi kontrolu ve profille acilis testi
echo [4/5] PowerShell 7 profili kontrol ediliyor...
for /f "delims=" %%R in ('pwsh -NoProfile -Command "$PROFILE"') do set "PROFILEPATH=%%R"
if not exist "!PROFILEPATH!" (
echo Profil dosyasi bulunamadi. Cokme nedeni bu degil. >> "%LOGFILE%"
echo Profil dosyasi bulunamadi. Cokme nedeni bu degil.
goto :ADIM5
)
echo Profil dosyasi bulundu: !PROFILEPATH! >> "%LOGFILE%"
echo Profil dosyasi bulundu: !PROFILEPATH!
echo.
echo Not: bu test yalnizca PowerShell'in profilinizi yuklerken bildirdigi
echo hata sayisini olcer. Hata vermeden konsolu tamamen dondurup kilitleyen
echo bir profili YAKALAMAZ - pencere yanit vermez hale gelirse elle kapatip
echo bu araci tekrar calistirin.
echo Not: yalnizca hata sayisi olculur, kilitlenmeler yakalanmaz. >> "%LOGFILE%"
echo.
echo Profil ILE acilis test ediliyor...
for /f "delims=" %%E in ('pwsh -Command "exit $Error.Count"') do set "ERRCOUNT=%%E"
if "!ERRCOUNT!"=="0" (
echo Profil ILE acilis, hicbir hata bildirilmeden tamamlandi. >> "%LOGFILE%"
echo Profil ILE acilis, hicbir hata bildirilmeden tamamlandi.
goto :ADIM5
)
echo Profil ILE acilis !ERRCOUNT! hata bildirdi. >> "%LOGFILE%"
echo Profil ILE acilis !ERRCOUNT! hata bildirdi.
echo Sorun buyuk ihtimalle profil betiginin icindedir. >> "%LOGFILE%"
echo.
set /p "YENIDENADCEVAP=Profil, PowerShell'in temiz baslamasi icin *.old olarak yeniden adlandirilsin mi? (E/H, varsayilan H): "
if /I not "!YENIDENADCEVAP!"=="E" (
echo Kullanici yeniden adlandirmayi atladi. Profilde degisiklik yapilmadi. >> "%LOGFILE%"
echo Yeniden adlandirma atlandi. Profilde degisiklik yapilmadi.
echo Oneri: !PROFILEPATH! dosyasini bir editorde acip elle inceleyin. >> "%LOGFILE%"
goto :ADIM5
)
pwsh -NoProfile -Command "Rename-Item -Path $PROFILE -NewName ($PROFILE + '.old') -ErrorAction Stop" 2>>"%LOGFILE%"
if %ERRORLEVEL%==0 (
echo Profil *.old olarak yeniden adlandirildi. PowerShell'i tekrar acmayi deneyin. >> "%LOGFILE%"
echo Profil *.old olarak yeniden adlandirildi. PowerShell'i tekrar acin.
) else (
echo Yeniden adlandirma basarisiz oldu - hata icin gunlugu inceleyin. Hicbir sey degistirilmedi. >> "%LOGFILE%"
echo Yeniden adlandirma basarisiz oldu - hata icin gunlugu inceleyin. Hicbir sey degistirilmedi.
)
:ADIM5
REM Adim 5 - Hermes calistirilabilir dosya hatirlatmasi
echo [5/5] Hermes for Windows hakkinda hatirlatma...
echo Hermes, pwsh.exe (PowerShell 7) uygulamasini cagiracak sekilde >> "%LOGFILE%"
echo ayarlanmalidir; powershell.exe (dahili Windows PowerShell 5.1) DEGIL. >> "%LOGFILE%"
echo Hermes'in kisayol/hedef alanindaki calistirilabilir dosya adini kontrol edin. >> "%LOGFILE%"
echo Hermes pwsh.exe cagirmali, powershell.exe degil. Kisayol ayarlarini kontrol edin.
:RAPOR
echo.
echo Tani raporu kaydedildi: "%LOGFILE%"
echo.
echo Press ENTER to exit.
pause >nul
endlocal
Versiyon -1
Kod: Tümünü seç
@echo off
chcp 65001 >nul
setlocal enabledelayedexpansion
set "DESKTOP=%USERPROFILE%\Desktop"
set "LOGFILE=%DESKTOP%\PowerShell_Tani_Raporu.txt"
echo PowerShell Tani ve Onarim Raporu > "%LOGFILE%"
echo Olusturulma: %DATE% %TIME% >> "%LOGFILE%"
echo. >> "%LOGFILE%"
echo ===================================================
echo PowerShell Tani ve Onarim Araci
echo ===================================================
echo.
REM Adim 1 - PowerShell 7 (pwsh.exe) kurulu mu kontrol edilir
echo [1/5] PowerShell 7 (pwsh.exe) kontrol ediliyor...
where pwsh >nul 2>&1
if %ERRORLEVEL%==0 (
echo PowerShell 7 PATH icinde bulundu. >> "%LOGFILE%"
echo PowerShell 7 PATH icinde bulundu.
) else (
echo PowerShell 7 PATH icinde bulunamadi. >> "%LOGFILE%"
echo PowerShell 7 PATH icinde bulunamadi.
echo Kurulum adresi: https://github.com/PowerShell/PowerShell/releases
echo Kurulum adresi: https://github.com/PowerShell/PowerShell/releases >> "%LOGFILE%"
goto :RAPOR
)
REM Adim 2 - pwsh -NoProfile ile acilis testi
echo [2/5] "pwsh -NoProfile" acilisi test ediliyor...
pwsh -NoProfile -Command "exit 0"
if %ERRORLEVEL%==0 (
echo pwsh -NoProfile basariyla acildi. >> "%LOGFILE%"
echo pwsh -NoProfile basariyla acildi.
) else (
echo pwsh -NoProfile acilamadi. Kurulum bozuk olabilir. >> "%LOGFILE%"
echo pwsh -NoProfile acilamadi. Kurulum bozuk olabilir.
echo Oneri: PowerShell 7'yi Ayarlar'dan kaldirip resmi kaynaktan >> "%LOGFILE%"
echo yeniden kurun. >> "%LOGFILE%"
echo Oneri: PowerShell 7'yi resmi kaynaktan yeniden kurun.
goto :RAPOR
)
REM Adim 3 - Execution Policy kontrolu
echo [3/5] Execution Policy kontrol ediliyor...
for /f "delims=" %%P in ('pwsh -NoProfile -Command "Get-ExecutionPolicy"') do set "EXECPOLICY=%%P"
echo Mevcut execution policy: !EXECPOLICY! >> "%LOGFILE%"
echo Mevcut execution policy: !EXECPOLICY!
if /I "!EXECPOLICY!"=="Restricted" (
echo UYARI: Restricted politikasi profil betiklerinin calismasini engelleyebilir. >> "%LOGFILE%"
echo UYARI: Restricted politikasi profil betiklerinin calismasini engelleyebilir.
)
REM Adim 4 - Profil dosyasi kontrolu ve profille acilis testi
echo [4/5] PowerShell profili kontrol ediliyor...
for /f "delims=" %%R in ('pwsh -NoProfile -Command "$PROFILE"') do set "PROFILEPATH=%%R"
if exist "!PROFILEPATH!" (
echo Profil dosyasi bulundu: !PROFILEPATH! >> "%LOGFILE%"
echo Profil dosyasi bulundu: !PROFILEPATH!
echo Profil ILE acilis test ediliyor...
pwsh -Command "exit 0"
if !ERRORLEVEL! NEQ 0 (
echo Profil ILE acilis basarisiz oldu. Sorun buyuk ihtimalle profildedir. >> "%LOGFILE%"
echo Profil ILE acilis basarisiz oldu. Sorun buyuk ihtimalle profildedir.
pwsh -NoProfile -Command "Rename-Item $PROFILE ($PROFILE + '.old') -ErrorAction SilentlyContinue"
echo Profil yedek olarak *.old uzantisiyla yeniden adlandirildi. >> "%LOGFILE%"
echo PowerShell'i tekrar acmayi deneyin. >> "%LOGFILE%"
echo Profil *.old olarak yedeklendi. PowerShell'i tekrar acin.
) else (
echo Profil ILE acilis basarili oldu. Sorun profilden kaynaklanmiyor. >> "%LOGFILE%"
echo Profil ILE acilis basarili oldu. Sorun profilden kaynaklanmiyor.
)
) else (
echo Profil dosyasi bulunamadi. Cokme nedeni bu degil. >> "%LOGFILE%"
echo Profil dosyasi bulunamadi. Cokme nedeni bu degil.
)
REM Adim 5 - Hermes calistirilabilir dosya hatirlatmasi
echo [5/5] Hermes for Windows hakkinda hatirlatma...
echo Hermes, pwsh.exe (PowerShell 7) uygulamasini cagiracak sekilde >> "%LOGFILE%"
echo ayarlanmalidir; powershell.exe (dahili Windows PowerShell 5.1) DEGIL. >> "%LOGFILE%"
echo Hermes'in kisayol/hedef alanindaki calistirilabilir dosya adini kontrol edin. >> "%LOGFILE%"
echo Hermes pwsh.exe cagirmali, powershell.exe degil. Kisayol ayarlarini kontrol edin.
:RAPOR
echo.
echo Tani raporu kaydedildi: "%LOGFILE%"
echo.
echo Press ENTER to exit.
pause >nul
endlocal
Betik ne yapıyor:
1.pwsh.exe PATH içinde var mı kontrol eder , yoksa kurulum linkini gösterir ve durur
2.pwsh -NoProfile ile açılış testi yapar , başarısızsa kurulumun bozuk olduğunu bildirir
3.Get-ExecutionPolicy çıktısını okur, Restricted ise uyarır
4.Profil dosyasının var olup olmadığını kontrol eder; profille açılış başarısızsa dosyayı otomatik olarak .old uzantısıyla yedekler (silmez, yeniden adlandırır , güvenli)
5.Hermes'in pwsh.exe mi yoksa powershell.exe mi çağırması gerektiğini hatırlatır
Ek bir betik daha..(Eğer Powershell ortamınızı onarabilirseniz) Profil dosyasını yedekleyen/geri yükleyen .ps1 betiği
PowerShellProfile_BackupRestore.TR.ps1
Kod: Tümünü seç
# PowerShellProfile_BackupRestore.TR.ps1
# PowerShell kullanıcı profilini yedeklemek ve geri yüklemek için basit menü tabanlı araç.
# Windows PowerShell 5.1 ve PowerShell 7.x ile uyumludur.
# UTF-8 encoding sabitleme bloğu (Türkçe karakterlerin doğru görüntülenmesi için)
$OutputEncoding = [System.Text.Encoding]::UTF8
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$DesktopPath = [Environment]::GetFolderPath("Desktop")
$BackupFolder = Join-Path $DesktopPath "PowerShell_Profil_Yedekleri"
if (-not (Test-Path $BackupFolder)) {
New-Item -ItemType Directory -Path $BackupFolder | Out-Null
}
function Show-Menu {
Clear-Host
Write-Host "==================================================="
Write-Host " PowerShell Profili Yedekleme ve Geri Yükleme Aracı"
Write-Host "==================================================="
Write-Host ""
Write-Host "Profil yolu : $PROFILE"
Write-Host "Yedek klasörü : $BackupFolder"
Write-Host ""
Write-Host "[1] Mevcut profili yedekle"
Write-Host "[2] En son yedeği geri yükle"
Write-Host "[3] Yedek listesinden seçerek geri yükle"
Write-Host "[4] Çıkış"
Write-Host ""
}
function Backup-Profile {
if (Test-Path $PROFILE) {
$timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
$backupName = "Profil_Yedek_$timestamp.ps1"
$backupPath = Join-Path $BackupFolder $backupName
Copy-Item -Path $PROFILE -Destination $backupPath -Force
Write-Host "Yedek oluşturuldu: $backupPath" -ForegroundColor Green
}
else {
Write-Host "Şu yolda profil dosyası bulunamadı: $PROFILE" -ForegroundColor Yellow
Write-Host "Yedeklenecek bir şey yok."
}
}
function Restore-SpecificBackup {
param($BackupFile)
$profileDir = Split-Path $PROFILE -Parent
if (-not (Test-Path $profileDir)) {
New-Item -ItemType Directory -Path $profileDir -Force | Out-Null
}
if (Test-Path $PROFILE) {
$safetyName = "Geri_Yukleme_Oncesi_Guvenlik_" + (Get-Date -Format "yyyyMMdd_HHmmss") + ".ps1"
$safetyPath = Join-Path $BackupFolder $safetyName
Copy-Item -Path $PROFILE -Destination $safetyPath -Force
Write-Host "Mevcut profil güvenlik kopyası olarak kaydedildi: $safetyPath" -ForegroundColor Cyan
}
Copy-Item -Path $BackupFile.FullName -Destination $PROFILE -Force
Write-Host "Profil şu yedekten geri yüklendi: $($BackupFile.Name)" -ForegroundColor Green
}
function Restore-LatestBackup {
$backups = Get-ChildItem -Path $BackupFolder -Filter "Profil_Yedek_*.ps1" -ErrorAction SilentlyContinue |
Sort-Object LastWriteTime -Descending
if ($backups.Count -eq 0) {
Write-Host "Şu klasörde yedek bulunamadı: $BackupFolder" -ForegroundColor Yellow
return
}
Restore-SpecificBackup -BackupFile $backups[0]
}
function Restore-FromList {
$backups = Get-ChildItem -Path $BackupFolder -Filter "Profil_Yedek_*.ps1" -ErrorAction SilentlyContinue |
Sort-Object LastWriteTime -Descending
if ($backups.Count -eq 0) {
Write-Host "Şu klasörde yedek bulunamadı: $BackupFolder" -ForegroundColor Yellow
return
}
Write-Host ""
for ($i = 0; $i -lt $backups.Count; $i++) {
Write-Host "[$($i + 1)] $($backups[$i].Name) ($($backups[$i].LastWriteTime))"
}
Write-Host ""
$choice = Read-Host "Geri yüklenecek yedeğin numarasını girin (iptal için C)"
if ($choice -eq "C" -or $choice -eq "c") {
return
}
$index = 0
$isNumeric = [int]::TryParse($choice, [ref]$index)
if (-not $isNumeric -or $index -lt 1 -or $index -gt $backups.Count) {
Write-Host "Geçersiz seçim." -ForegroundColor Red
return
}
Restore-SpecificBackup -BackupFile $backups[$index - 1]
}
# Ana döngü
$running = $true
while ($running) {
Show-Menu
$selection = Read-Host "Bir seçenek seçin"
switch ($selection) {
"1" { Backup-Profile }
"2" { Restore-LatestBackup }
"3" { Restore-FromList }
"4" { $running = $false }
default { Write-Host "Geçersiz seçenek." -ForegroundColor Red }
}
if ($running) {
Write-Host ""
Read-Host "Devam etmek için ENTER'a basın"
}
}
Read-Host "`nPress ENTER to exit."
Kod: Tümünü seç
# PowerShellProfile_BackupRestore_TR.ps1
# Windows PowerShell 5.1 ve PowerShell 7.x profil dosyalarını tarayan,
# yedekleyen ve geri yükleyen; kullanıcının seçtiği yedek klasörünü
# hatırlayarak bir sonraki çalıştırmada tekrar sormayan araç.
$OutputEncoding = [System.Text.Encoding]::UTF8
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$ConfigDir = Join-Path $env:APPDATA "PowerShellProfileBackupTool"
$ConfigFile = Join-Path $ConfigDir "settings.json"
function Get-PS7Home {
$cmd = Get-Command "pwsh.exe" -ErrorAction SilentlyContinue
if ($cmd) {
return Split-Path $cmd.Source -Parent
}
$candidate = Join-Path $env:ProgramFiles "PowerShell\7"
if (Test-Path $candidate) {
return $candidate
}
return $null
}
function Get-ProfileDefinitions {
$documents = [Environment]::GetFolderPath("MyDocuments")
$winPSHome = Join-Path $env:WINDIR "System32\WindowsPowerShell\v1.0"
$ps7Home = Get-PS7Home
$definitions = New-Object System.Collections.Generic.List[object]
$definitions.Add([PSCustomObject]@{
Id = "WinPS51_CurrentUser_AllHosts"
Label = "Windows PowerShell 5.1 - Kullanıcı - Tüm Hostlar"
Path = Join-Path $documents "WindowsPowerShell\profile.ps1"
})
$definitions.Add([PSCustomObject]@{
Id = "WinPS51_CurrentUser_CurrentHost"
Label = "Windows PowerShell 5.1 - Kullanıcı - Konsol Host"
Path = Join-Path $documents "WindowsPowerShell\Microsoft.PowerShell_profile.ps1"
})
$definitions.Add([PSCustomObject]@{
Id = "WinPS51_AllUsers_AllHosts"
Label = "Windows PowerShell 5.1 - Tüm Kullanıcılar - Tüm Hostlar"
Path = Join-Path $winPSHome "profile.ps1"
})
$definitions.Add([PSCustomObject]@{
Id = "WinPS51_AllUsers_CurrentHost"
Label = "Windows PowerShell 5.1 - Tüm Kullanıcılar - Konsol Host"
Path = Join-Path $winPSHome "Microsoft.PowerShell_profile.ps1"
})
$definitions.Add([PSCustomObject]@{
Id = "PS7_CurrentUser_AllHosts"
Label = "PowerShell 7.x - Kullanıcı - Tüm Hostlar"
Path = Join-Path $documents "PowerShell\profile.ps1"
})
$definitions.Add([PSCustomObject]@{
Id = "PS7_CurrentUser_CurrentHost"
Label = "PowerShell 7.x - Kullanıcı - Konsol Host"
Path = Join-Path $documents "PowerShell\Microsoft.PowerShell_profile.ps1"
})
if ($ps7Home) {
$definitions.Add([PSCustomObject]@{
Id = "PS7_AllUsers_AllHosts"
Label = "PowerShell 7.x - Tüm Kullanıcılar - Tüm Hostlar"
Path = Join-Path $ps7Home "profile.ps1"
})
$definitions.Add([PSCustomObject]@{
Id = "PS7_AllUsers_CurrentHost"
Label = "PowerShell 7.x - Tüm Kullanıcılar - Konsol Host"
Path = Join-Path $ps7Home "Microsoft.PowerShell_profile.ps1"
})
}
else {
Write-Host "PowerShell 7.x kurulumu tespit edilemedi; yalnızca Windows PowerShell 5.1 profilleri taranacak." -ForegroundColor Yellow
}
$seenPaths = New-Object System.Collections.Generic.HashSet[string] ([StringComparer]::OrdinalIgnoreCase)
foreach ($def in $definitions) {
[void]$seenPaths.Add($def.Path)
}
# Bu aracı çalıştıran oturumun bildirdiği gerçek $PROFILE yollarını da
# listeye ekle. Bu, standart isimler dışında bir profil dosya adı
# kullanan host'ları (örneğin bir IDE'nin tümleşik terminalini) yakalar.
$runtimeMap = [ordered]@{
"AllUsersAllHosts" = "Mevcut Oturum - Tüm Kullanıcılar - Tüm Hostlar"
"AllUsersCurrentHost" = "Mevcut Oturum - Tüm Kullanıcılar - $($Host.Name)"
"CurrentUserAllHosts" = "Mevcut Oturum - Kullanıcı - Tüm Hostlar"
"CurrentUserCurrentHost" = "Mevcut Oturum - Kullanıcı - $($Host.Name)"
}
foreach ($key in $runtimeMap.Keys) {
$path = $PROFILE.$key
if ($path -and -not $seenPaths.Contains($path)) {
$definitions.Add([PSCustomObject]@{
Id = "Runtime_$key"
Label = $runtimeMap[$key]
Path = $path
})
[void]$seenPaths.Add($path)
}
}
# Visual Studio Code'un tümleşik terminali kendi profil dosya adını kullanır.
$vscodeCandidates = @(
[PSCustomObject]@{ Id = "VSCode_WinPS51_CurrentUser"; Label = "Windows PowerShell 5.1 - Kullanıcı - VS Code Host"; Path = Join-Path $documents "WindowsPowerShell\Microsoft.VSCode_profile.ps1" }
[PSCustomObject]@{ Id = "VSCode_PS7_CurrentUser"; Label = "PowerShell 7.x - Kullanıcı - VS Code Host"; Path = Join-Path $documents "PowerShell\Microsoft.VSCode_profile.ps1" }
)
foreach ($cand in $vscodeCandidates) {
if (-not $seenPaths.Contains($cand.Path)) {
$definitions.Add($cand)
[void]$seenPaths.Add($cand.Path)
}
}
return $definitions
}
function Get-SavedBackupRoot {
if (Test-Path $ConfigFile) {
try {
$settings = Get-Content -Path $ConfigFile -Raw | ConvertFrom-Json
if ($settings.BackupRoot) {
return $settings.BackupRoot
}
}
catch {
return $null
}
}
return $null
}
function Save-BackupRoot {
param([string]$Path)
if (-not (Test-Path $ConfigDir)) {
New-Item -ItemType Directory -Path $ConfigDir -Force | Out-Null
}
$settings = [PSCustomObject]@{ BackupRoot = $Path }
$settings | ConvertTo-Json | Set-Content -Path $ConfigFile -Encoding UTF8
}
function Read-BackupRoot {
$saved = Get-SavedBackupRoot
if ($saved) {
Write-Host "Kayıtlı yedek klasörü bulundu: $saved"
$answer = Read-Host "Bu klasör kullanılsın mı? (E/H, varsayılan E)"
if ([string]::IsNullOrWhiteSpace($answer) -or $answer -eq "E" -or $answer -eq "e") {
if (-not (Test-Path $saved)) {
New-Item -ItemType Directory -Path $saved -Force | Out-Null
}
return $saved
}
}
$defaultPath = Join-Path ([Environment]::GetFolderPath("Desktop")) "PowerShell_Profil_Yedekleri"
$userInput = Read-Host "Yedek klasörü yolunu girin (varsayılan için boş bırakın: $defaultPath)"
$chosen = if ([string]::IsNullOrWhiteSpace($userInput)) { $defaultPath } else { $userInput }
if (-not (Test-Path $chosen)) {
New-Item -ItemType Directory -Path $chosen -Force | Out-Null
}
Save-BackupRoot -Path $chosen
return $chosen
}
function Set-NewBackupRoot {
$userInput = Read-Host "Yeni yedek klasörü yolunu girin"
if ([string]::IsNullOrWhiteSpace($userInput)) {
Write-Host "Yol girilmedi, klasör değiştirilmedi." -ForegroundColor Yellow
return $script:BackupRoot
}
if (-not (Test-Path $userInput)) {
New-Item -ItemType Directory -Path $userInput -Force | Out-Null
}
Save-BackupRoot -Path $userInput
Write-Host "Yedek klasörü güncellendi: $userInput" -ForegroundColor Green
return $userInput
}
function Show-DetectedProfiles {
$definitions = Get-ProfileDefinitions
Write-Host ""
Write-Host "Tespit edilen profil yolları:"
Write-Host ""
foreach ($def in $definitions) {
$status = if (Test-Path $def.Path) { "Bulundu" } else { "Bulunamadı" }
Write-Host ("[{0}] {1}" -f $status, $def.Label)
Write-Host (" {0}" -f $def.Path)
}
Write-Host ""
}
function Backup-Profiles {
param([string]$BackupRoot)
$definitions = Get-ProfileDefinitions
$existing = $definitions | Where-Object { Test-Path $_.Path }
if ($existing.Count -eq 0) {
Write-Host "Yedeklenecek profil dosyası bulunamadı." -ForegroundColor Yellow
return
}
$timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
$sessionName = "Yedek_$timestamp"
$sessionPath = Join-Path $BackupRoot $sessionName
New-Item -ItemType Directory -Path $sessionPath -Force | Out-Null
$manifest = @()
foreach ($def in $existing) {
$destName = "$($def.Id).ps1"
$destPath = Join-Path $sessionPath $destName
try {
Copy-Item -Path $def.Path -Destination $destPath -Force -ErrorAction Stop
$manifest += [PSCustomObject]@{
Id = $def.Id
Label = $def.Label
OriginalPath = $def.Path
FileName = $destName
}
Write-Host "Yedeklendi: $($def.Label)" -ForegroundColor Green
Write-Host " Kaynak: $($def.Path)"
}
catch {
Write-Host "Yedeklenemedi: $($def.Label)" -ForegroundColor Red
Write-Host " $($_.Exception.Message)"
}
}
if ($manifest.Count -eq 0) {
Write-Host "Hiçbir dosya yedeklenemedi." -ForegroundColor Yellow
Remove-Item -Path $sessionPath -Recurse -Force -ErrorAction SilentlyContinue
return
}
$manifestPath = Join-Path $sessionPath "manifest.json"
$manifest | ConvertTo-Json | Set-Content -Path $manifestPath -Encoding UTF8
Write-Host ""
Write-Host "Yedekleme tamamlandı. Yedek seti kaydedildi: $sessionPath" -ForegroundColor Green
}
function Get-BackupSets {
param([string]$BackupRoot)
if (-not (Test-Path $BackupRoot)) {
return @()
}
Get-ChildItem -Path $BackupRoot -Directory -Filter "Yedek_*" -ErrorAction SilentlyContinue |
Where-Object { Test-Path (Join-Path $_.FullName "manifest.json") } |
Sort-Object LastWriteTime -Descending
}
function Restore-BackupSet {
param([System.IO.DirectoryInfo]$SessionFolder)
$manifestPath = Join-Path $SessionFolder.FullName "manifest.json"
$manifest = Get-Content -Path $manifestPath -Raw | ConvertFrom-Json
$safetyRoot = Join-Path $SessionFolder.FullName ("Geri_Yükleme_Öncesi_Güvenlik_" + (Get-Date -Format "yyyyMMdd_HHmmss"))
$restoredCount = 0
foreach ($entry in $manifest) {
$sourceFile = Join-Path $SessionFolder.FullName $entry.FileName
if (-not (Test-Path $sourceFile)) {
Write-Host "Yedek dosyası eksik, atlandı: $($entry.FileName)" -ForegroundColor Yellow
continue
}
$targetDir = Split-Path $entry.OriginalPath -Parent
try {
if (-not (Test-Path $targetDir)) {
New-Item -ItemType Directory -Path $targetDir -Force | Out-Null
}
if (Test-Path $entry.OriginalPath) {
if (-not (Test-Path $safetyRoot)) {
New-Item -ItemType Directory -Path $safetyRoot -Force | Out-Null
}
$safetyName = "$($entry.Id).ps1"
Copy-Item -Path $entry.OriginalPath -Destination (Join-Path $safetyRoot $safetyName) -Force
}
Copy-Item -Path $sourceFile -Destination $entry.OriginalPath -Force -ErrorAction Stop
Write-Host "Geri yüklendi: $($entry.Label)" -ForegroundColor Green
Write-Host " Hedef: $($entry.OriginalPath)"
$restoredCount++
}
catch {
Write-Host "Geri yüklenemedi: $($entry.Label)" -ForegroundColor Red
Write-Host " $($_.Exception.Message)"
}
}
Write-Host ""
if ($restoredCount -gt 0) {
Write-Host "Geri yükleme tamamlandı. $restoredCount profil dosyası geri yüklendi." -ForegroundColor Green
}
else {
Write-Host "Hiçbir profil dosyası geri yüklenmedi." -ForegroundColor Yellow
}
if (Test-Path $safetyRoot) {
Write-Host "Geri yükleme öncesi güvenlik kopyaları kaydedildi: $safetyRoot" -ForegroundColor Cyan
}
}
function Restore-LatestBackupSet {
param([string]$BackupRoot)
$sets = Get-BackupSets -BackupRoot $BackupRoot
if ($sets.Count -eq 0) {
Write-Host "Şu klasörde yedek seti bulunamadı: $BackupRoot" -ForegroundColor Yellow
return
}
Restore-BackupSet -SessionFolder $sets[0]
}
function Restore-FromBackupList {
param([string]$BackupRoot)
$sets = Get-BackupSets -BackupRoot $BackupRoot
if ($sets.Count -eq 0) {
Write-Host "Şu klasörde yedek seti bulunamadı: $BackupRoot" -ForegroundColor Yellow
return
}
Write-Host ""
for ($i = 0; $i -lt $sets.Count; $i++) {
Write-Host "[$($i + 1)] $($sets[$i].Name) ($($sets[$i].LastWriteTime))"
}
Write-Host ""
$choice = Read-Host "Geri yüklenecek yedek setinin numarasını girin (iptal için C)"
if ($choice -eq "C" -or $choice -eq "c") {
return
}
$index = 0
$isNumeric = [int]::TryParse($choice, [ref]$index)
if (-not $isNumeric -or $index -lt 1 -or $index -gt $sets.Count) {
Write-Host "Geçersiz seçim." -ForegroundColor Red
return
}
Restore-BackupSet -SessionFolder $sets[$index - 1]
}
function Show-Menu {
param([string]$BackupRoot)
Clear-Host
Write-Host "==================================================="
Write-Host " PowerShell Profili Yedekleme ve Geri Yükleme Aracı"
Write-Host "==================================================="
Write-Host ""
Write-Host "Aracı çalıştıran PowerShell sürümü : $($PSVersionTable.PSVersion)"
Write-Host "Yedek klasörü : $BackupRoot"
Write-Host ""
Write-Host "[1] Mevcut profilleri yedekle"
Write-Host "[2] En son yedek setini geri yükle"
Write-Host "[3] Yedek setleri listesinden seçerek geri yükle"
Write-Host "[4] Tespit edilen profil yollarını göster"
Write-Host "[5] Yedek klasörünü değiştir"
Write-Host "[6] Çıkış"
Write-Host ""
}
# Ana döngü
$BackupRoot = Read-BackupRoot
$running = $true
while ($running) {
Show-Menu -BackupRoot $BackupRoot
$selection = Read-Host "Bir seçenek seçin"
switch ($selection) {
"1" { Backup-Profiles -BackupRoot $BackupRoot }
"2" { Restore-LatestBackupSet -BackupRoot $BackupRoot }
"3" { Restore-FromBackupList -BackupRoot $BackupRoot }
"4" { Show-DetectedProfiles }
"5" { $BackupRoot = Set-NewBackupRoot }
"6" { $running = $false }
default { Write-Host "Geçersiz seçenek." -ForegroundColor Red }
}
if ($running) {
Write-Host ""
Read-Host "Devam etmek için ENTER'a basın"
}
}
Read-Host "`nPress ENTER to exit."

Kod: Tümünü seç
$Host.Name
>> Test-Path $PROFILE.CurrentUserCurrentHost
>> $PROFILE | Format-List *- burak35
- Zettabyte4

- Mesajlar: 18238
- Kayıt: 07 Eki 2016, 13:06
- cinsiyet: Erkek
- Teşekkür etti: 10624 kez
- Teşekkür edildi: 12421 kez
Re: Powershel hatası
sıfırdan temiz kurulum işe yarayabilir. tabikide kullanılan hesap admin olursa iyi olur diye tahmin ediyorum.
- Kayserilifatih
- Exabyte1

- Mesajlar: 10416
- Kayıt: 30 Ağu 2024, 20:48
- cinsiyet: Erkek
- Teşekkür etti: 973 kez
- Teşekkür edildi: 7786 kez
Re: Powershel hatası
Bende de PowerShell çalışmıyor Allah'tan fazla işim düşmüyor da sorun olmuyor. Kullandığım sistem 11 25H2 9168 yapısı
