programing

윈도우즈 서버 2016의 모든 PowerShell 세션에서 명령 기록을 보려면 어떻게 해야 합니까?

oldcodes 2023. 7. 3. 23:09
반응형

윈도우즈 서버 2016의 모든 PowerShell 세션에서 명령 기록을 보려면 어떻게 해야 합니까?

윈도우즈 서버 2016의 모든 세션에서 전체 기록을 볼 수 있는 위치는 어디입니까?

다음 PowerShell 명령에는 현재 세션의 명령만 포함됩니다.

Get-History

PowerShell에 다음 명령을 입력합니다.

(Get-PSReadlineOption).HistorySavePath

모든 기록이 저장되는 경로를 제공합니다.그런 다음 텍스트 편집기에서 경로를 엽니다.

해라cat (Get-PSReadlineOption).HistorySavePathPowerShell에 기록을 나열합니다.

PowerShell에서 전체 기록을 가져오고 출력을 파일에 저장하려면 다음 명령을 사용합니다.

Get-Content (Get-PSReadlineOption).HistorySavePath > D:\PowerShellHistory.txt

윈도우즈의 경우 PowerShell

사용할 수 있는 세션에 참여하려면h또는history

하지만 사용하는 컴퓨터에 모든 명령을 기록합니다.

cat (Get-PSReadlineOption).HistorySavePath

당신은 윈도우에 있기 때문에 아래를 사용하여 '노트패드'를 열 수도 있습니다.

notepad (Get-PSReadlineOption).HistorySavePath

Windows Server/Enterprise 버전에 대해서는 언급이 있지만 Pro(표준 소매 버전) 사용자로서HistorySavePath저도 이용할 수 있습니다.저는 최근에 이전 세션에서 어떤 파이썬 패키지가 설치되었는지 확인해야 했고 역사에서 특정한 것을 찾는 사람들을 위해 여기에 답을 추가하고 싶었습니다.

# if you like file names and line numbers included in your output
Select-String "<search pattern>" (Get-PSReadlineOption).HistorySavePath

# if you Just want the text without any of the other information
Get-Content (Get-PSReadlineOption).HistorySavePath | Select-String "<search pattern>" 

저 같은 경우에는 도망쳤습니다.

Select-String 'pip install' (Get-PSReadlineOption).HistorySavePath

이전 세션에서 실행된 pip 설치 명령 목록을 제공했습니다.

...
[Path/To/File]:10401:pip install dash
[Path/To/File]:10824:pip install -r .\requirements.txt
[Path/To/File]:11296:pip install flask-mysqldb
[Path/To/File]:11480:pip install Flask-Markdown
[Path/To/File]:11486:pip install pygments
[Path/To/File]:11487:pip install py-gfm
[Path/To/File]:11540:pip install bs4

Powershell 갤러리의 Psreadline 모듈 2.1 베타1(Powershell 7에만 해당) https://www.powershellgallery.com/packages/PSReadLine/2.1.0-beta1 은 저장된 기록을 사용하여 명령줄에서 인텔리전스를 인식합니다. https://github.com/PowerShell/PSReadLine/issues/1468 Vcode에 표시되기 시작했습니다.https://www.reddit.com/r/PowerShell/comments/g33503/completion_on_history_in_vscode/

또한 Psreadline에서는 f8(명령줄에 무언가를 입력한 후) 또는 control-R을 사용하여 저장된 기록을 역방향으로 검색할 수 있습니다.Get-ps readline 키 처리기는 키 바인딩을 나열합니다.

get-psreadlinekeyhandler -bound -unbound | ? function -match history

이 PowerShell 명령 기록을 사용해 볼 수 있습니다.

언급URL : https://stackoverflow.com/questions/44104043/how-can-i-see-the-command-history-across-all-powershell-sessions-in-windows-serv

반응형