PowerShell/Functionの一覧および内容を表示する方法
の編集
Top
/
PowerShell
/
Functionの一覧および内容を表示する方法
[
トップ
] [
編集
|
差分
|
バックアップ
|
添付
|
リロード
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
-- 雛形とするページ --
(no template pages)
#navi(../) * PowerShellのFunctionの一覧および内容を表示する方法 [#z7a32f3a] PowerShellの関数である、Functionの一覧を表示する方法を以下に記します。~ 使用したPowerShellのバージョンは、以下の通りです。 PS C:\> $PSVersionTable.PSVersion Major Minor Build Revision ----- ----- ----- -------- 5 0 10586 63 #contents #htmlinsertpcsp(win-top.html,win-sp.html) * Functionの一覧および内容を表示する方法 [#tc1f044c] 以下の構文でFunctionの一覧を表示することができます。 Get-ChildItem -path function: また、以下のように操作しても同様の結果となります。 Set-Location function: Get-ChildItem 元に戻すときには、Cドライブであれば、c:と入力しEnterキーを押せば戻ります。 * Functionの内部(定義)を見る方法 [#ve162fa7] 以下のように操作すると、指定したFunctionのスクリプトを見ることができます。 ** clear-host [#k1a18e4c] PS C:\Users\Sakura> Get-Item function:clear-host CommandType Name Version Source ----------- ---- ------- ------ Function Clear-Host PS C:\Users\Sakura> (Get-Item function:clear-host).Definition $space = New-Object System.Management.Automation.Host.BufferCell $space.Character = ' ' $space.ForegroundColor = $host.ui.rawui.ForegroundColor $space.BackgroundColor = $host.ui.rawui.BackgroundColor $rect = New-Object System.Management.Automation.Host.Rectangle $rect.Top = $rect.Bottom = $rect.Right = $rect.Left = -1 $origin = New-Object System.Management.Automation.Host.Coordinates $Host.UI.RawUI.CursorPosition = $origin $Host.UI.RawUI.SetBufferContents($rect, $space) # .Link # http://go.microsoft.com/fwlink/?LinkID=225747 # .ExternalHelp System.Management.Automation.dll-help.xml **prompt [#k125b064] PS C:\Users\Sakura> Get-Item Function:\prompt CommandType Name Version Source ----------- ---- ------- ------ Function prompt PS C:\Users\Sakura> (Get-Item Function:\prompt).Definition "PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) " # .Link # http://go.microsoft.com/fwlink/?LinkID=225750 # .ExternalHelp System.Management.Automation.dll-help.xml * 実際にFunctionを作って確認してみる [#o584c180] 以下のようにメッセージを引数として受け取り表示する関数を作成し確認してみます。 PS C:\Users\Sakura> Function SayHi($msg="") { Write-Output "Hi! $msg" } PS C:\Users\Sakura> SayHi Sakura Hi! Sakura PS C:\Users\Sakura> Get-ChildItem Function:\SayHi CommandType Name Version Source ----------- ---- ------- ------ Function SayHi PS C:\Users\Sakura> (Get-ChildItem Function:\SayHi).Definition param($msg="") Write-Output "Hi! $msg" 以上、PowerShellのFunction一覧の表示および、Functionのスクリプト内容を表示する方法でした。 #htmlinsertpcsp(win-btm.html,win-sp.html)
タイムスタンプを変更しない
#navi(../) * PowerShellのFunctionの一覧および内容を表示する方法 [#z7a32f3a] PowerShellの関数である、Functionの一覧を表示する方法を以下に記します。~ 使用したPowerShellのバージョンは、以下の通りです。 PS C:\> $PSVersionTable.PSVersion Major Minor Build Revision ----- ----- ----- -------- 5 0 10586 63 #contents #htmlinsertpcsp(win-top.html,win-sp.html) * Functionの一覧および内容を表示する方法 [#tc1f044c] 以下の構文でFunctionの一覧を表示することができます。 Get-ChildItem -path function: また、以下のように操作しても同様の結果となります。 Set-Location function: Get-ChildItem 元に戻すときには、Cドライブであれば、c:と入力しEnterキーを押せば戻ります。 * Functionの内部(定義)を見る方法 [#ve162fa7] 以下のように操作すると、指定したFunctionのスクリプトを見ることができます。 ** clear-host [#k1a18e4c] PS C:\Users\Sakura> Get-Item function:clear-host CommandType Name Version Source ----------- ---- ------- ------ Function Clear-Host PS C:\Users\Sakura> (Get-Item function:clear-host).Definition $space = New-Object System.Management.Automation.Host.BufferCell $space.Character = ' ' $space.ForegroundColor = $host.ui.rawui.ForegroundColor $space.BackgroundColor = $host.ui.rawui.BackgroundColor $rect = New-Object System.Management.Automation.Host.Rectangle $rect.Top = $rect.Bottom = $rect.Right = $rect.Left = -1 $origin = New-Object System.Management.Automation.Host.Coordinates $Host.UI.RawUI.CursorPosition = $origin $Host.UI.RawUI.SetBufferContents($rect, $space) # .Link # http://go.microsoft.com/fwlink/?LinkID=225747 # .ExternalHelp System.Management.Automation.dll-help.xml **prompt [#k125b064] PS C:\Users\Sakura> Get-Item Function:\prompt CommandType Name Version Source ----------- ---- ------- ------ Function prompt PS C:\Users\Sakura> (Get-Item Function:\prompt).Definition "PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) " # .Link # http://go.microsoft.com/fwlink/?LinkID=225750 # .ExternalHelp System.Management.Automation.dll-help.xml * 実際にFunctionを作って確認してみる [#o584c180] 以下のようにメッセージを引数として受け取り表示する関数を作成し確認してみます。 PS C:\Users\Sakura> Function SayHi($msg="") { Write-Output "Hi! $msg" } PS C:\Users\Sakura> SayHi Sakura Hi! Sakura PS C:\Users\Sakura> Get-ChildItem Function:\SayHi CommandType Name Version Source ----------- ---- ------- ------ Function SayHi PS C:\Users\Sakura> (Get-ChildItem Function:\SayHi).Definition param($msg="") Write-Output "Hi! $msg" 以上、PowerShellのFunction一覧の表示および、Functionのスクリプト内容を表示する方法でした。 #htmlinsertpcsp(win-btm.html,win-sp.html)
テキスト整形のルールを表示する