사용자 도구

사이트 도구


windows:powershell

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
windows:powershell [2018/05/30 18:51]
kwon37xi
windows:powershell [2024/03/05 13:00] (현재)
kwon37xi
줄 1: 줄 1:
 ====== Windows Powershell ====== ====== Windows Powershell ======
   * https://powershell.org/   * https://powershell.org/
 +  * [[:starship|Starship]]
   * [[https://github.com/PowerShell/PowerShell/tree/master/docs/learning-powershell|Learning Powershell]]   * [[https://github.com/PowerShell/PowerShell/tree/master/docs/learning-powershell|Learning Powershell]]
   * [[https://github.com/JanDeDobbeleer/oh-my-posh|oh-my-posh]]   * [[https://github.com/JanDeDobbeleer/oh-my-posh|oh-my-posh]]
   * [[https://mva.microsoft.com/en-us/training-courses/getting-started-with-powershell-3-0-jump-start-8276?l=r54IrOWy_2304984382|Microsoft PowerShell Tutorial & Training Course – Microsoft Virtual Academy]]   * [[https://mva.microsoft.com/en-us/training-courses/getting-started-with-powershell-3-0-jump-start-8276?l=r54IrOWy_2304984382|Microsoft PowerShell Tutorial & Training Course – Microsoft Virtual Academy]]
 +  * [[https://github.com/fleschutz/PowerShell|fleschutz/PowerShell: Mega collection of 250+ useful cross-platform PowerShell scripts.]]
  
 ===== 기본 개인 profile 파일 ===== ===== 기본 개인 profile 파일 =====
-  * ''$PROFILE'' 환경변수값+  * [[https://technet.microsoft.com/en-us/library/bb613488(v=vs.85).aspx|Understanding profile]] 
 +  * ''$PROFILE'' 환경변수 값으로 프로필 파일 생성<code> 
 +New-Item $profile -force -itemtype file 
 +</code>
   * ''$Home\[My ]Documents\WindowsPowerShell\Profile.ps1''   * ''$Home\[My ]Documents\WindowsPowerShell\Profile.ps1''
- 
- 
 ===== Powershell Core ===== ===== Powershell Core =====
   * [[https://blogs.msdn.microsoft.com/powershell/2018/01/10/powershell-core-6-0-generally-available-ga-and-supported/|Powershell Core 6.0 GA Linux / MacOS X Support]]   * [[https://blogs.msdn.microsoft.com/powershell/2018/01/10/powershell-core-6-0-generally-available-ga-and-supported/|Powershell Core 6.0 GA Linux / MacOS X Support]]
줄 24: 줄 27:
 Import-Module Get-ChildItemColor Import-Module Get-ChildItemColor
  
-Set-Alias Get-ChildItemColor -option AllScope +Set-Alias ls Get-ChildItemColor -option AllScope 
-Set-Alias ls Get-ChildItemColorFormatWide -option AllScope+Set-Alias ll Get-ChildItemColorFormatWide -option AllScope
 </code> </code>
  
줄 37: 줄 40:
   * [[https://blogs.endjin.com/2016/02/improve-your-windows-command-prompt-and-powershell-experience-with-conemu/|Improve your Windows Command Prompt and PowerShell experience with ConEmu | endjin blog]]   * [[https://blogs.endjin.com/2016/02/improve-your-windows-command-prompt-and-powershell-experience-with-conemu/|Improve your Windows Command Prompt and PowerShell experience with ConEmu | endjin blog]]
   * https://hodgkins.io/ultimate-powershell-prompt-and-git-setup   * https://hodgkins.io/ultimate-powershell-prompt-and-git-setup
 +
 +===== process 목록 =====
 +<code sh>
 +ps *foo*
 +get-process | findstr foo
 +get-process | where ProcessName -like "*foo*"
 +</code>
 +
 +===== 환경변수 Environment Variable =====
 +  * [[https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-6|about_Environment_Variables | Microsoft Docs]]
 +<code>
 +#값 읽기
 +$Env:<variable-name>
 +$Env:PATH
 +
 +# 값 지정
 +$Env:<variable-name> = "<new-value>"
 +
 +$Env:path = $env:path + ";c:\temp"
 +Set-Item -Path Env:Path -Value ($Env:Path + ";C:\Temp")
 +
 +# 환경변수 목록
 +Get-ChildItem Env:
 +</code>
 +
 +===== 기본명령 =====
 +  * 디렉토리 삭제<code>
 +Remove-Item [dirname] -Force
 +</code>
 +  * Symoblic Link<code>
 +# 관리자 권한 필요
 +New-Item -ItemType SymbolicLink -Name MySymLinkFile.txt -Target $pshome\profile.ps1
 +New-Item -ItemType SymbolicLink -Path C:\Temp\MySymLinkFile.txt -Value $pshome\profile.ps1
 +</code>
 +  * grep 대체 [[https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/select-string?view=powershell-6|Select-String]]<code>
 +# 문자열 filter
 +"Hello","HELLO" | Select-String -Pattern "HELLO" -CaseSensitive
 +# *.xml 파일들에서 문자열 탐색
 +Select-String -Path "*.xml" -Pattern "the the"
 +
 +# 매칭이 안되는 부분 찾기
 +Select-String -Path "process.txt" -Pattern "idle, svchost" -NotMatch
 +</code>
 +  * rename - [[https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/rename-item?view=powershell-6|Rename-Item]]<code>
 +Rename-Item -Path old_name -NewName new_name [-Force]
 +</code>
 +===== curl =====
 +  * [[linux:curl|Curl]] 을 사용하려면 ''cinst curl''로 설치하고
 +  * ''$profile'' 파일에 PowerShell에 자체 ''curl'' alias를 지워야 실제 ''curl'' 명령이 실행된다.<code>
 +remove-item alias:curl
 +</code>
 +
 +===== wget =====
 +  * ''wget'' 명령은 ''Invoke-WebRequest''의 alias 이다. [[https://superuser.com/questions/362152/native-alternative-to-wget-in-windows-powershell|Native alternative to wget in Windows PowerShell?]]
 +
 +<code sh>
 +wget http://blog.stackexchange.com/ -OutFile out.html
 +</code>
 +
 +===== Powershell script from remote =====
 +  * [[https://www.thomasmaurer.ch/2021/07/powershell-download-script-or-file-from-github/|PowerShell: Download script or file from GitHub - Thomas Maurer]]
 +
 +<code sh>
 +Invoke-WebRequest -Uri https://raw.githubusercontent.com/thomasmaurer/demo-cloudshell/master/helloworld.ps1 -OutFile .\helloworld.ps1; .\helloworld.ps1 
 +</code>
 +  * [[https://www.youtube.com/watch?v=omm2YUkTkg0|How to run a Powershell script directly from Github private repository through Powershell - YouTube]] : github api 와 access token 으로 원격 스크립트 실행.
 +<code sh>
 +# Created by Daniel Jean Schmidt
 +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
 +
 +$Script = Invoke-RestMethod https://api.github.com/repos/Twikki/youtubetest/contents/Download_Files.ps1?access_token=yourtokenhere -Headers @{”Accept”= “application/vnd.github.v3.raw”}
 +
 +Invoke-Expression $Script
 +</code>
 +  * [[https://tomtalks.blog/run-powershell-scripts-directly-github-two-lines/|Run PowerShell Scripts Directly from GitHub with Two Lines - Tom Talks]]
 +
 +<code>
 +# script 주소는 올바르게 변경할 것.
 +$ScriptFromGitHub = Invoke-WebRequest https://raw.githubusercontent.com/tomarbuthnot/Run-PowerShell-Directly-From-GitHub/master/Run-FromGitHub-SamplePowerShell.ps1
 +Invoke-Expression $($ScriptFromGitHub.Content)
 +</code>
 +===== tail =====
 +마지막 1000 줄 보여주면서 계속 출력하기
 +
 +<code sh>
 +Get-Content 파일경로 -Wait -Tail 1000
 +</code>
 +
 +===== alias =====
 +<code>
 +# vi 를 vim.exe 실행하는 것으로 alias 걸기
 +set-alias -name vi -value vim.exe
 +</code>
 +
 +===== Timezone =====
 +  * [[https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/set-timezone?view=powershell-6|Set-TimeZone]]
 +
 +<code>
 +Set-TimeZone -Id "Korea Standard Time"
 +</code>
 +
 +=====언어 변경 =====
 +  * 언어팩은 설정을 통해서만 다운로드 가능하다. 명령행으로 현재까지는 불가함.
 +    * [[https://docs.microsoft.com/ko-kr/windows-hardware/manufacture/desktop/add-language-packs-to-windows#get-languages|Add languages to Windows images | Microsoft Docs]] 언어팩을 다운로드 하려면 라이센스 가입을 통해 ISO 파일을 다운로드 받아야 함.
 +<code>
 +# 가능할수도? 테스트 필요.
 +Get-WindowsCapability -Online | ? Name -like '*ko*' # 한국어 관련 목록 버전을 정확히 확인해야함.
 +
 +Add-WindowsCapability -Online -Name 'Language.Basic~~~ko-KR~0.0.1.0'
 +Add-WindowsCapability -Online -Name 'Lnaguage.Fonts.Kore~~~und-KORE~0.0.1.0'
 +</code>
 +  * [[https://4sysops.com/archives/adding-and-removing-keyboard-languages-with-powershell/|Adding and removing keyboard languages with PowerShell – 4sysops]]
 +  * [[https://4sysops.com/archives/local-experience-packs-add-languages-to-windows-10-and-server-2019/|Local Experience Packs: Add languages to Windows 10 and Server 2019 – 4sysops]]
 +  * [[https://docs.microsoft.com/en-us/powershell/module/international/set-winuilanguageoverride?view=win10-ps|Set-WinUILanguageOverride]]
 +  * [[https://docs.microsoft.com/en-us/powershell/module/international/set-winsystemlocale?view=win10-ps|Set-WinSystemLocale]]
 +<code>
 +Set-WinUILanguageOverride -Language ko-KR
 +Set-WinSystemLocale -SystemLocale ko-KR # 재부팅 후 적용
 +</code>
 +
 +===== Location 변경 =====
 +  * [[https://docs.microsoft.com/en-us/powershell/module/international/set-winhomelocation?view=win10-ps|Set-WinHomeLocation]]
 +  * [[https://docs.microsoft.com/en-us/powershell/module/international/get-winhomelocation?view=win10-ps|Get-WinHomeLocation]]
 +  * [[https://docs.microsoft.com/ko-kr/windows/win32/intl/table-of-geographical-locations?redirectedfrom=MSDN|Table of Geographical Locations - Win32 apps]] 지역 코드값
 +  * 한국 : ''134'' -> HEX ''0x86''
 +
 +<code>
 +Set-WinHomeLocation -GeoId 0x86
 +</code>
 +
 +===== Reboot =====
 +  * https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/restart-computer?view=powershell-7
 +
 +<code sh>
 +Restart-Computer
 +</code>
 +
 +===== Linux PowerShell =====
 +  * [[https://learn.microsoft.com/ko-kr/powershell/scripting/install/installing-powershell-on-linux|Installing PowerShell on Linux]]
 +  * [[https://learn.microsoft.com/ko-kr/powershell/scripting/install/install-ubuntu|Ubuntu에 PowerShell 설치]]
  
 ===== 참조 ===== ===== 참조 =====
   * [[https://gist.github.com/jchandra74/5b0c94385175c7a8d1cb39bc5157365e|PowerShell, Cmder / ConEmu, Posh-Git, Oh-My-Posh, Powerline Customization]]   * [[https://gist.github.com/jchandra74/5b0c94385175c7a8d1cb39bc5157365e|PowerShell, Cmder / ConEmu, Posh-Git, Oh-My-Posh, Powerline Customization]]
 +  * [[https://www.tutorialspoint.com/powershell/index.htm|Powershell Tutorial]]
  
windows/powershell.1527673911.txt.gz · 마지막으로 수정됨: 2018/05/30 18:51 저자 kwon37xi