29/12/2018

Windows PowerShell Profile Prompt History

Powershell de de aynı linux gibi prompt vs kabiliyetler mevcut. Örneğin Administrator user ının powershell profile dosyası

C:\Users\Administrator\Documents\WindowsPowerShell> Microsoft.PowerShell_profile.ps1

ile editleniyor. Özellikle Prompt ta hostname yazmasını istiyordum. Ayrıca Normalde powershell history i session içinde tutuyor yani pencere kapanınca history de gidiyordu. Bunu da engellemek istiyordum

İnternetten şu kodu indirdim ve editledim. History yi bir csv ye export edip import ederek bir problemi funtion prompt ile de diğerini çözüyor. Harika değil üzerinde çok uğraşmadım henüz ancak iş görüyor.

#region History
$PSProfileFolder = Split-Path -Path $PROFILE
$PSHistoryPath = "$PSProfileFolder\History.csv"
$PSMaximumHistoryCount = 4096
if (!(Test-Path $PSProfileFolder -PathType Container)) {
        New-Item $PSProfileFolder -ItemType Directory -Force
}
if (Test-path $PSHistoryPath) {
        Import-CSV $PSHistoryPath | Add-History
}
Register-EngineEvent PowerShell.Exiting -Action {
        Get-History -Count $PSMaximumHistoryCount | Export-CSV $PSHistoryPath
    [enviroment]::Exit(0)
} | out-null
#endregion History
$Hostname=hostname
function prompt { 'PS ' + $Hostname+'@'+$pwd + '> ' }

Ayrıca şu linki buldum beğendim üzerinde çalışıp burayı update etmem gerekecek.

https://www.howtogeek.com/298244/how-to-use-your-command-history-in-windows-powershell/

]]>

Leave a Reply