bashやzshなどでは、vimやEmacsを使ってファイルの編集が可能です。 PowerShellでも同様に扱えますが、PowerShell ISEもpowershell_ise.exeではなくpseditコマンドというショートカットでファイルを開いて編集できます。
PowerShell ISE
本ブログでも何度も紹介しているPowerShell ISE (Integrated Scripting Environment)です。
win + r > powershell_iseなどで起動することが出来るPowerShell純正の開発環境です。
psedit
pseditはPowerShell ISE専用コマンドレットの1つです。 概要を見てみましょう。
PS> Get-Command psedit | select * HelpUri : ScriptBlock : param([Parameter(Mandatory=$true)]$filenames) foreach ($filename in $filenames) { dir $filename | where {!$_.PSIsContainer} | %{ $psISE.CurrentPowerShellTab.Files.Add($_.FullName) > $null } } CmdletBinding : True DefaultParameterSet : Definition : param([Parameter(Mandatory=$true)]$filenames) foreach ($filename in $filenames) { dir $filename | where {!$_.PSIsContainer} | %{ $psISE.CurrentPowerShellTab.Files.Add($_.FullName) > $null } } Options : None Description : Verb : Noun : HelpFile : OutputType : {} Name : psEdit CommandType : Function Visibility : Public ModuleName : Module : RemotingCapability : PowerShell Parameters : {[filenames, System.Management.Automation.ParameterMetadata], [Verbose, System.Management.Automation.ParameterMetadata], [Debug, System.Management.Automation.ParameterMetadata], [ErrorAction, System.Management.Automation.ParameterMetadata]...} ParameterSets : {[-filenames] <Object> [<CommonParameters>]}
Helpを見てみましょう
PS> Get-Help psedit -full NAME psEdit SYNTAX psEdit [-filenames] <Object> [<CommonParameters>] PARAMETERS -filenames <Object> Required? true Position? 0 Accept pipeline input? false Parameter set name (All) Aliases None Dynamic? false <CommonParameters> This cmdlet supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningVariable, OutBuffer and OutVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). INPUTS None OUTPUTS System.Object ALIASES None REMARKS None
利用方法
PowerShell_iseのコンソール画面下(上部のScripting部分ではなく、下部のコンソール部分) で、 psedit ファイル名とするだけです。
例えば、このようなファイルを出力します。
Get-Help psedit -full | Out-File -FilePath d:\test.log -Encoding utf8
PowerShell ISEのスクリプト部分でファイルを開きましょう。
psedit D:\test.log
とても便利なので利用してください。 なお、 powershell.exeでpseditコマンドは利用できません。
powershell_iseで開くだけなら普通に引数に渡せばいいのですが、コマンドが長く微妙ですね。
powershell_ise D:\test.log