「PowerShell」の版間の差分

削除された内容 追加された内容
Ef3 (トーク | 投稿記録)
from:https://en.wikibooks.org/w/index.php?title=Introduction_to_.NET_Framework_3.0/Windows_PowerShell&oldid=3321278
タグ: 2017年版ソースエディター
Ef3 (トーク | 投稿記録)
和訳。Runspaceをどう訳すか迷いましたが、ランスペースとしました。
タグ: 2017年版ソースエディター
1 行
{{.NET Framework 3.0}}
 
Windows PowerShell '''(codenamed:Monad)''' is a command-line driven interface (CLI). It is not supplied with older versions of Windows Vista, but it could be used, regardless, in Windows XP, Windows 2003 Server and Windows Vista.
----
Windows PowerShell '''(コードネーム:Monad)'''は、コマンドライン駆動のインターフェース(CLI)です。古いバージョンのWindows Vistaには付属していませんが、Windows XP、Windows 2003 Server、Windows Vistaでは関係なく使用することができました。
 
Windows PowerShell is the foundation of the administrative tools for Exchange Server 2007, System Center Virtual Machine Manager 2007 and System Center Operations Manager 2007 where everything is done via command line interfaces and the administrative GUI is layered on top of those commands.
----
 
Windows PowerShellは、Exchange Server 2007、System Center Virtual Machine Manager 2007、System Center Operations Manager 2007の管理ツールの基盤となっており、すべての操作をコマンドラインインターフェイスで行い、その上に管理用のGUIを重ねています。
 
== Working ==
----
== 動作 ==
 
Windows PowerShell works according to a system called "Monadology" according to which the whole earth is composed of metaphysical structures not connected to each other called monads. The "monads" of Windows PowerShell are objects called "cmdlets". Following the failure of Windows Script Host, Microsoft started working on Windows PowerShell as early as 2003. Unlike Windows Script Host, Windows Powershell interacts directly with the shell and is highly secure.
----
Windows PowerShellは、地球全体がモナドと呼ばれる互いに接続されていない形而上学的な構造で構成されているという「モナドロジー」と呼ばれるシステムに基づいて動作します。Windows PowerShellの「モナド」は「コマンドレット」と呼ばれるオブジェクトです。Windows Script Hostの失敗を受けて、マイクロソフト社は2003年にはWindows PowerShellの開発に着手しました。Windows Script Hostとは異なり、Windows PowerShellはシェルと直接対話し、高い安全性を備えています。
 
Instead of services which use pipes or streams data in order to communicate with each, Windows Powershell uses object-to-object communication between two cmdlets in different remote machines. A listing of processes will consist not of text describing them, but objects representing them, so that methods can be called on those objects without explicit reference to any outside structure or library.
----
Windows Powershellは、パイプを使ったり、データをストリームしたりして通信するサービスではなく、異なるリモートマシンにある2つのコマンドレット間でオブジェクト間通信を行います。プロセスのリストは、プロセスを説明するテキストではなく、プロセスを表すオブジェクトで構成され、外部の構造体やライブラリを明示的に参照することなく、それらのオブジェクトに対してメソッドを呼び出すことができます。
 
Windows PowerShell operates within a hosting application (the default is powershell.exe) that exposes a command line to the user and uses a host interface to communicate with the commands invoked by the command line. The hosting application can be a console application, a Windows application, or a Web application. In most cases, the hosting application uses its ''Main'' function to interact with the Windows PowerShell runtime through the internal host interface; however, a hosting application can optionally support its own custom host by implementing the PSHost class along with one or more related user interface classes. Together, these classes allow direct communication between the application and Windows PowerShell commands.
----
Windows PowerShellはホスティングアプリケーション(デフォルトはpowershell.exe)の中で動作し、ユーザーにコマンドラインを公開し、コマンドラインから呼び出されるコマンドとの通信にホストインターフェースを使用します。ホスティングアプリケーションには、コンソールアプリケーション、Windowsアプリケーション、またはWebアプリケーションがあります。ほとんどの場合、ホスティングアプリケーションは、その「Main」関数を使用して、内部ホストインターフェースを介してWindows PowerShellランタイムと対話します。しかし、ホスティングアプリケーションは、オプションとして、PSHostクラスと1つ以上の関連するユーザーインターフェースクラスを実装することで、独自のカスタムホストをサポートすることができます。これらのクラスを併用することで、アプリケーションとWindows PowerShellコマンドの間の直接通信が可能になります。
 
=== Creating a Runspace ===
----
=== ランスペースの作成 ===
 
The first thing that the hosting application must do in communicating with the Windows PowerShell runtime is to create a runspace, which is the abstraction of the Windows PowerShell runtime used to simplify a user session. To do this, the hosting application calls the CreateRunspace method of the RunspaceFactory class. The runspace itself is represented by a Runspace object. In addition, Windows PowerShell provides the RunspaceConfiguration class to define the configuration of the runspace. Configuration information includes data about commands and Windows PowerShell providers that the hosting application supports, and startup scripts for the runspace. User scripts are not reflected in the runspace configuration. When a runspace is created, a corresponding session is automatically opened, with its state represented by a SessionState object. Session state data includes information about Windows PowerShell paths, Windows PowerShell drives, Windows PowerShell providers, plus cmdlets and other commands that are active during the session.
----
ホスティング・アプリケーションがWindows PowerShellランタイムと通信する際に最初にしなければならないことは、ユーザー・セッションを簡略化するために使用されるWindows PowerShellランタイムの抽象化であるランスペースを作成することです。これを行うために、ホスティングアプリケーションは、RunspaceFactoryクラスのCreateRunspaceメソッドを呼び出します。ランスペース自体は、Runspaceオブジェクトで表されます。さらに、Windows PowerShellは、ランスペースの構成を定義するためにRunspaceConfigurationクラスを提供します。構成情報には、ホストアプリケーションがサポートするコマンドやWindows PowerShellプロバイダに関するデータ、およびランスペースのスタートアップスクリプトが含まれます。ユーザースクリプトは、ランスペースの構成には反映されません。ランスペースが作成されると、対応するセッションが自動的に開かれ、その状態はSessionStateオブジェクトで表されます。セッションの状態データには、Windows PowerShellのパス、Windows PowerShellのドライブ、Windows PowerShellのプロバイダ、およびセッション中にアクティブなコマンドレットやその他のコマンドに関する情報が含まれます。
 
=== Opening the Runspace ===
----
=== ランスペースのオープン ===
 
When the hosting application has created a runspace, it must open the runspace for the type of session that is required. For a session using synchronous I/O, the application can call the Open method. If the application uses asynchronous I/O and must perform other operations while the runspace fulfills a read/write request, it can call the OpenAsync method. If calling OpenAsync, a hosting application defining a custom host will need to support an appropriate callback method to receive I/O notifications.
----
ホストアプリケーションがランスペースを作成したら、必要なセッションの種類に合わせてランスペースを開く必要があります。同期I/Oを使用するセッションの場合、アプリケーションはOpenメソッドを呼び出します。アプリケーションが非同期I/Oを使用し、ランスペースが読み取り/書き込み要求を満たす間に他の操作を行う必要がある場合は、OpenAsyncメソッドを呼び出すことができます。OpenAsync を呼び出す場合、カスタム・ホストを定義しているホスト・アプリケーションは、I/O 通知を受け取るための適切なコールバック・メソッドをサポートする必要があります。
 
When the runspace is opened, the hosting application can manipulate the session by creating and invoking pipelines in the runspace, as described in Processing Commands.
----
ランスペースがオープンされると、「コマンドの処理」で説明したように、ホスティングアプリケーションはランスペースでパイプラインを作成して起動することで、セッションを操作できます。
 
The runspace allows the hosting application to manipulate the session with calls to the GetVariable and SetVariable methods of the SessionStateProxy object for the session.
----
ランスペースでは、SessionStateProxyオブジェクトのGetVariableおよびSetVariableメソッドを呼び出すことで、ホスティング・アプリケーションがセッションを操作することができます。
 
=== Creating a Pipeline ===
----
=== パイプラインの作成 ===
 
When the hosting application has accumulated a command sequence from the user, it must form the commands into one or more pipelines, each represented by a Pipeline object for the active runspace.
----
ホスト・アプリケーションがユーザからのコマンド・シーケンスを蓄積した場合、そのコマンドを1つまたは複数のパイプラインにまとめる必要があります。
 
A command sequence can be made up of multiple nested pipelines, separated by semicolon (;) statement separators. Here's an example of such a sequence.
----
 
コマンド・シーケンスは、セミコロン(;)で区切られた複数のネストされたパイプラインから構成されます。以下にその例を示します。
PS>pqr | bar; a | b
<source lang="powershell">
 
PS C:\Users\User1> pqr | bar; a | b
</source>
The Windows PowerShell runtime represents this sequence as one pipeline with two nested pipelines, pqr | bar and a | b.
----
Windows PowerShellのランタイムは、このシーケンスを、pqr|barとa|bという2つのネストしたパイプラインを持つ1つのパイプラインとして表現します。
 
To create its own pipeline, the hosting application calls either the CreatePipeline method or the CreateNestedPipeline method. The application calls CreatePipeline to form an empty pipeline or if it must create a pipeline and populate it with commands. If the application must create a pipeline for a runspace with its current pipeline executing, it must call CreateNestedPipeline.
----
独自のパイプラインを作成するために、ホスティングアプリケーションはCreatePipelineメソッドまたはCreateNestedPipelineメソッドを呼び出します。空のパイプラインを作成する場合や、パイプラインを作成してコマンドを入力する必要がある場合、アプリケーションはCreatePipelineを呼び出します。現在のパイプラインが実行されているランスペースにパイプラインを作成する必要がある場合、アプリケーションはCreateNestedPipelineを呼び出す必要があります。
 
=== Starting the Pipeline ===
----
=== パイプラインの開始 ===
 
Now that its pipeline is set up, the hosting application must start its operation. If the application is using synchronous I/O, it calls the Invoke method, using the variant for either an empty pipeline or a populated one. For asynchronous I/O, the application can call InvokeAsync instead.
----
パイプラインが設定されたので、ホスト・アプリケーションはその動作を開始する必要があります。アプリケーションが同期I/Oを使用している場合、Invokeメソッドを呼び出し、空のパイプラインまたは入力されたパイプラインのいずれかのバリアントを使用します。非同期I/Oの場合、アプリケーションは代わりにInvokeAsyncを呼び出すことができます。
 
== Features ==
----
== 機能 ==
 
The first version contains the following features:
54 ⟶ 91行目:
* Comprehensive, user-extensible tab completion features. The cmd.exe shell in current versions of Windows can only complete file or directory names, in contrast to the advanced completion in shells such as Bash and zsh.
* The ability to assign the output of a command to a variable, which will then be an object or array of objects inspectable in any way desired.
----
最初のバージョンには、以下の機能が含まれています。
* C#ライクなスクリプト言語で、ハッシュテーブル、正規表現をテストできるswitch文、配列のスライス、データとして保存して後で実行できる匿名メソッド(スクリプトブロック)をサポートしています。また、ループ(for/foreach/while)、条件文(if/switch)、変数のスコープ(global/script/local)、関数を定義する機能も備えています。
* Cmdlets は特定のオプションを継承しており、ユーザーはインタラクションのレベルやエラーへの対処方法などを選択できます。副作用を発生させる Cmdlets は、オプション <code>-WhatIf</code> と <code>-Confirm</code> をサポートしています。<code>-WhatIf</code>は、起こったであろうことをユーザに知らせますが、アクションは起こりません。<code>-Confirm</code>は、何が起ころうとしているのかをユーザに知らせ、ユーザがそれを実行するかどうかをコントロールできるようにします。
* エラーに対処するための1つのオプションは、ユーザーが新しいコマンドシェルに入り、問題を調査した後、元のコマンドを再開することができる「サスペンド」機能を呼び出すことです。ユーザーはこのような状況で表示されるプロンプトを定義することができます。
* 拡張可能な''プロバイダー''モデルにより、ファイルシステムやその他の階層的なデータストアへのアクセスや操作が可能です。いくつか例を挙げます。PowerShell には、「HKLM」および「HKCU」ハイブを介したレジストリへのアクセスを可能にするレジストリプロバイダが付属しています。これにより、シェルプロンプトで「dir HKLM:\SOFTWARE\Microsoft」などのコマンドを実行することで、レジストリを参照することができます。PowerShell には、証明書ストア、環境、シェル関数およびエイリアス用のプロバイダが付属しています。コマンドレットと同様に、プロバイダモデルは拡張可能であり、サードパーティが独自のプロバイダモデルを作成し、PowerShellにプラグインすることができます。
* PowerShell スクリプトの実行時に粗いセキュリティ制約を課すことができる「実行ポリシー」と呼ばれる概念です。実行ポリシーは、PowerShellが設定ファイルをロードし、スクリプトを実行する際の制限を定義します。実行ポリシーには、「Restricted」、「AllSigned」、「RemoteSigned」、「Unrestricted」の4種類があります。
* スクリプトの発行者の身元を確認し、デジタル署名を使用して発行されたスクリプトの整合性を検証するスクリプト署名の使用をサポートします。
* コマンドラインオプションは、基本的には単語全体ですが、曖昧さをなくすために必要最小限の文字数で指定することができます。例えば、<code>-show-detailed-information</code>というオプションは、他に's'で始まるオプションがなければ、<code>-s</code>と入力することができます。
* 包括的でユーザーが拡張可能なタブ補完機能。現行バージョンの Windows の cmd.exe シェルは、Bash や zsh などのシェルの高度な補完機能とは対照的に、ファイル名やディレクトリ名しか補完できません。
* コマンドの出力を変数に代入することができ、変数は任意の方法で検査可能なオブジェクトまたはオブジェクトの配列になります。
 
== References ==
----
== 参考文献 ==
 
# [http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx]