「PowerShell」の版間の差分

削除された内容 追加された内容
Ef3 (トーク | 投稿記録)
cat.
タグ: 2017年版ソースエディター
Ef3 (トーク | 投稿記録)
原文を抹消
タグ: 2017年版ソースエディター
 
1 行
{{wikipedia|PowerShell}}
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 ===
----
=== ランスペースの作成 ===
ホスティング・アプリケーションがWindows PowerShellランタイムと通信する際に最初にしなければならないことは、ユーザー・セッションを簡略化するために使用されるWindows PowerShellランタイムの抽象化であるランスペース( ''Runspace'' )を作成することです。これを行うために、ホスティングアプリケーションは、RunspaceFactoryクラスのCreateRunspaceメソッドを呼び出します。ランスペース自体は、Runspaceオブジェクトで表されます。さらに、Windows PowerShellは、ランスペースの構成を定義するためにRunspaceConfigurationクラスを提供します。構成情報には、ホストアプリケーションがサポートするコマンドやWindows PowerShellプロバイダに関するデータ、およびランスペースのスタートアップスクリプトが含まれます。ユーザースクリプトは、ランスペースの構成には反映されません。ランスペースが作成されると、対応するセッションが自動的に開かれ、その状態はSessionStateオブジェクトで表されます。セッションの状態データには、Windows PowerShellのパス、Windows PowerShellのドライブ、Windows PowerShellのプロバイダ、およびセッション中にアクティブなコマンドレットやその他のコマンドに関する情報が含まれます。
 
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.
----
コマンド・シーケンスは、セミコロン(;)で区切られた複数のネストされたパイプラインから構成されます。以下にその例を示します。
<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:
* A C#-like scripting language with support for hash tables, switch statements which can test on regular expressions, array slicing and anonymous methods (script blocks) which can be stored as data and then later executed. It also provides looping (for/foreach/while), conditional statements (if/switch), variable scoping (global/script/local) and the ability to define functions.
* Cmdlets inherit certain options, allowing the user to choose things such as the level of interaction and how to deal with errors. Cmdlets which produce side effects support the options <code>-WhatIf</code> and <code>-Confirm</code>. <code>-WhatIf</code> informs the user what would have happened, but no action takes place. <code>-Confirm</code> informs the user what is about to happen and allows the user to control whether it takes place or not.
* One option for dealing with errors is to invoke a "suspend" feature which allows the user to enter a new command shell, investigate a problem, and resume the original command. The user can define the prompts to be shown in such circumstances.
* An extensible ''provider'' model allows access to and manipulation of the file system and other hierarchical data stores. Some examples: PowerShell comes with a registry provider which allows access to the registry via the "HKLM" and "HKCU" hives; with this, the registry can be browsed by executing commands like "dir HKLM:\SOFTWARE\Microsoft" at the shell prompt. PowerShell comes with providers for the certificate store, the environment, and shell functions and aliases. Like cmdlets, the provider model is extensible, allowing third parties to create their own provider model and plug it into PowerShell.
* A concept called "execution policies" which allows coarse security constraints to be imposed upon PowerShell script execution. Execution policies define the restrictions under which PowerShell loads configuration files and runs scripts. The four execution policies are Restricted, AllSigned, RemoteSigned, and Unrestricted.
* Support for the use of script signing to verify the identity of a script publisher and to validate the integrity of a published script using digital signatures.
* The command-line options are generally whole words, but they can be specified as the minimum number of letters necessary to disambiguate. For example, the option <code>-show-detailed-information</code> could be entered as <code>-s</code> if no other option begins with 's'.
* 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)、関数を定義する機能も備えています。
104 ⟶ 50行目:
* コマンドの出力を変数に代入することができ、変数は任意の方法で検査可能なオブジェクトまたはオブジェクトの配列になります。
 
== References ==
----
== 参考文献 ==