windows:powershell

PowerShell(Windows)

PowerShell - Linux

本家: PowerShell Documentation | Microsoft Docs
ソースコード: GitHub - PowerShell/PowerShell: PowerShell for every system!
最新バージョン: v7.3.6

PowerShell
PowerShell (パワーシェル)は、マイクロソフトが開発した拡張可能なコマンドラインインターフェース (CLI) シェルおよびスクリプト言語である。オブジェクト指向に基づいて設計されており、.NET Frameworkと.NET Coreを基盤としている。

かつては Microsoft Shell (MSH、コードネーム Monad) と呼ばれていた。

Windows 7 以降のオペレーティングシステム (OS) には標準で搭載されている。

Scoop によるインストール

dorado バケットを追加する😉

PS > scoop bucket add dorado https://github.com/chawyehsu/dorado

Checking repo... ok
The dorado bucket was added successfully.

PowerShell のインストール

PS > scoop install powershell

Installing 'powershell' (7.3.6) [64bit]
PowerShell-7.3.6-win-x64.zip (102.9 MB) [=====================================================================] 100%
Checking hash of PowerShell-7.3.6-win-x64.zip ... ok.
Extracting PowerShell-7.3.6-win-x64.zip ... done.
Linking ~\scoop\apps\powershell\current => ~\scoop\apps\powershell\7.3.6
Creating shim for 'pwsh'.
Creating shortcut for PowerShell (pwsh.exe)
'powershell' (7.3.6) was installed successfully!

PowerShell のグローバルインストール

PS > sudo scoop install -g powershell

Installing 'powershell' (7.0.0) [64bit]
PowerShell-7.0.0-win-x64.zip (88.7 MB) [======================================================================] 100%
Checking hash of PowerShell-7.0.0-win-x64.zip ... ok.
Extracting PowerShell-7.0.0-win-x64.zip ... done.
Linking C:\ProgramData\scoop\apps\powershell\current => C:\ProgramData\scoop\apps\powershell\7.0.0
Creating shim for 'pwsh'.
Creating shortcut for PowerShell (pwsh.exe)
'powershell' (7.0.0) was installed successfully!

PowerShell(Preview版) のインストール

PS > scoop install powershell-preview

Installing 'powershell-preview' (7.0.0-rc.3) [64bit]
PowerShell-7.0.0-rc.3-win-x64.zip (88.8 MB) [=================================================================] 100%
Checking hash of PowerShell-7.0.0-rc.3-win-x64.zip ... ok.
Extracting PowerShell-7.0.0-rc.3-win-x64.zip ... done.
Linking ~\scoop\apps\powershell-preview\current => ~\scoop\apps\powershell-preview\7.0.0-rc.3
Creating shim for 'pwsh'.
WARN  Overwriting shim to pwsh.exe installed from powershell
Creating shortcut for PowerShell Preview (pwsh.exe)
'powershell-preview' (7.0.0-rc.3) was installed successfully!

$ less (Get-PSReadlineOption).HistorySavePath
$ cat (Get-PSReadlineOption).HistorySavePath | grep "scoop search"

PowerShell Gallery | Home
PowerShell ギャラリー

PowerShellGet をインストールするには、以下のコマンドを実行する。

$ sudo Install-Module -Name PowerShellGet -Force

PowerShellGet を新しいバージョンに更新するには、以下のコマンドを実行する。

$ sudo Update-Module -Name PowerShellGet

参考文献
PowerShell ギャラリー - PowerShell | Microsoft Docs
PowerShellGet のインストール - PowerShell | Microsoft Docs

現在のコンソール設定をバックアップする。

$ concfg export console-backup.json
console settings exported to console-backup.json

ソラリゼーションカラーテーマを使用する。

$ concfg import solarized-dark
Console settings were imported from 'solarized-dark'
Overrides in the registry and shortcut files might interfere with your concfg settings. Would you like to find and remove them? (Y/n): y <- 入力する
Removing 'Registry::HKEY_CURRENT_USER\Console\%SystemRoot%_System32_WindowsPowerShell_v1.0_powershell.exe'
Removing 'Registry::HKEY_CURRENT_USER\Console\%SystemRoot%_SysWOW64_WindowsPowerShell_v1.0_powershell.exe'
Reset console properties of shortcut 'C:\Users\tomoyan\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows PowerShell\Windows PowerShell (x86).lnk'
Reset console properties of shortcut 'C:\Users\tomoyan\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows PowerShell\Windows PowerShell.lnk'

Would you like to open a new console to see the changes? (Y/n): n <- 入力する

上記の翻訳

Overrides in the registry and shortcut files might interfere with your concfg settings. Would you like to find and remove them?
レジストリファイルおよびショートカットファイルのオーバーライドは、concfg設定に干渉する可能性があります。それらを見つけて削除しますか?
Would you like to open a new console to see the changes?
変更を確認するために新しいコンソールを開きますか?
PS > Get-Host
 
Name             : ConsoleHost
Version          : 6.2.4
InstanceId       : 3a2ed9d0-2c0b-42d5-976a-459d8e3f07af
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : ja-JP
CurrentUICulture : ja-JP
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace
 
PS > Get-Host | Select-Object Version
 
Version
-------
6.2.4
 
PS > $PSVersiontable
 
Name                           Value
----                           -----
PSVersion                      6.2.4
PSEdition                      Core
GitCommitId                    6.2.4
OS                             Microsoft Windows 10.0.19559
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
PS > start-process notepad c:\windows\system32\drivers\etc\hosts -verb runas
PS C:\Windows\System32> cd ~
PS C:\Users\tomoyan> pwd
 
Path
----
C:\Users\tomoyan
PS > start-process net -argumentlist "start postgresql-x64-11" -verb runas
PS > start-process net -argumentlist "stop postgresql-x64-11" -verb runas
  • windows/powershell.txt
  • 最終更新: 2023/10/06 14:49
  • by ともやん