Add-PSSnapin
現在のセッションに 1 つ以上の Windows PowerShell スナップインを追加します。
構文
Default (既定)
Add-PSSnapin
[-Name] <String[]>
[-PassThru]
[<CommonParameters>]
説明
Add-PSSnapin コマンドレットは、登録済みの Windows PowerShell スナップインを現在のセッションに追加します。 スナップインが追加されたら、現在のセッションでスナップインでサポートされているコマンドレットとプロバイダーを使用できます。
今後のすべての Windows PowerShell セッションにスナップインを追加するには、Windows PowerShell プロファイルに Add-PSSnapin コマンドを追加します。 詳細については、「about_Profiles」を参照してください。
Windows PowerShell 3.0 以降、Windows PowerShell に含まれるコア コマンドはモジュールにパッケージ化されています。 例外は、スナップイン (PSSnapin) である Microsoft.PowerShell.Core です。 既定では、Microsoft.PowerShell.Core スナップインのみがセッションに追加されます。 モジュールは最初の使用時に自動的にインポートされ、Import-Module コマンドレットを使用してインポートできます。
例
例 1: スナップインを追加する
PS C:\> Add-PSSnapIn -Name Microsoft.Exchange, Microsoft.Windows.AD
このコマンドは、Microsoft Exchange スナップインと Active Directory スナップインを現在のセッションに追加します。
例 2: 登録されているすべてのスナップインを追加する
PS C:\> Get-PSSnapin -Registered | Add-PSSnapin -Passthru
このコマンドは、登録されているすべての Windows PowerShell スナップインをセッションに追加します。 Get-PSSnapin コマンドレットと Registered パラメーターを使用して、登録済みの各スナップインを表すオブジェクトを取得します。パイプライン演算子 (|) は結果を Add-PSSnapin に渡し、Add-PSSnapin によってセッションに追加されます。 PassThru パラメーターは、追加された各スナップインを表すオブジェクトを返します。
例 3: スナップインを登録して追加する
The first command gets snap-ins that have been added to the current session that include the snap-ins that are installed with Windows PowerShell. In this example, ManagementFeatures is not returned. This indicates that it has not been added to the session.
PS C:\> Get-PSSnapin
The second command gets snap-ins that have been registered on your system, which includes those that have already been added to the session. It does not include the snap-ins that are installed with Windows PowerShell. In this case, the command does not return any snap-ins. This indicates that the ManagementFeatures snapin has not been registered on the system.
PS C:\> Get-PSSnapin -Registered
The third command creates an alias, installutil, for the path of the InstallUtil tool in .NET Framework.
PS C:\> Set-Alias installutil $env:windir\Microsoft.NET\Framework\v2.0.50727\installutil.exe
The fourth command uses the InstallUtil tool to register the snap-in. The command specifies the path of ManagementCmdlets.dll, the file name or module name of the snap-in.
PS C:\> installutil C:\Dev\Management\ManagementCmdlets.dll
The fifth command is the same as the second command. This time, you use it to verify that the ManagementCmdlets snap-in is registered.
PS C:\> Get-PSSnapin -Registered
The sixth command uses the **Add-PSSnapin** cmdlet to add the ManagementFeatures snap-in to the session. It specifies the name of the snap-in, ManagementFeatures, not the file name.
PS C:\> add-pssnapin ManagementFeatures
To verify that the snap-in is added to the session, the seventh command uses the *Module* parameter of the Get-Command cmdlet. It displays the items that were added to the session by a snap-in or module.
PS C:\> Get-Command -Module ManagementFeatures
You can also use the **PSSnapin** property of the object that the **Get-Command** cmdlet returns to find the snap-in or module in which a cmdlet originated. The eighth command uses dot notation to find the value of the PSSnapin property of the Set-Alias cmdlet.
PS C:\> (Get-Command Set-Alias).pssnapin
この例では、システムにスナップインを登録し、それをセッションに追加するプロセスを示します。 ManagementFeatures を使用します。これは、ManagementCmdlets.dllという名前のファイルに実装された架空のスナップインです。
パラメーター
-Name
スナップインの名前を指定します。 これは名前であり、AssemblyName または ModuleName ではありません。 ワイルドカードを使用できます。
システムに登録されているスナップインの名前を検索するには、「Get-PSSnapin -Registered」と入力します。
パラメーターのプロパティ
| 型: | String[] |
| 規定値: | None |
| ワイルドカードのサポート: | False |
| DontShow: | False |
パラメーター セット
(All)
| 配置: | 0 |
| 必須: | True |
| パイプラインからの値: | False |
| プロパティ名別のパイプラインからの値: | True |
| 残りの引数からの値: | False |
-PassThru
このコマンドレットは、追加された各スナップインを表すオブジェクトを返します。 既定では、このコマンドレットは出力を生成しません。
パラメーターのプロパティ
| 型: | SwitchParameter |
| 規定値: | None |
| ワイルドカードのサポート: | False |
| DontShow: | False |
パラメーター セット
(All)
| 配置: | Named |
| 必須: | False |
| パイプラインからの値: | False |
| プロパティ名別のパイプラインからの値: | False |
| 残りの引数からの値: | False |
CommonParameters
このコマンドレットでは、一般的なパラメーター -Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction、-WarningVariable の各パラメーターがサポートされています。 詳細については、about_CommonParametersを参照してください。
入力
None
このコマンドレットにオブジェクトをパイプすることはできません。
出力
None or System.Management.Automation.PSSnapInInfo
このコマンドレットは、PassThru パラメーターを指定した場合にスナップインを表す PSSnapInInfo オブジェクトを返します。 それ以外の場合、このコマンドレットは出力を生成しません。
メモ
Windows PowerShell 3.0 以降では、Windows PowerShell と共にインストールされるコア コマンドはモジュールにパッケージ化されています。 Windows PowerShell 2.0 と、それ以降のバージョンの Windows PowerShell で古いスタイルのセッションを作成するホスト プログラムでは、コア コマンドはスナップイン (PSSnapins) にパッケージ化されています。 例外は Microsoft.PowerShell.Core です。これは常にスナップインです。 また、New-PSSession コマンドレットによって開始されたリモート セッションは、コア スナップインを含む古いスタイルのセッションです。
コア モジュールを使用して新しいスタイルのセッションを作成する CreateDefault2 メソッドの詳細については、MSDN ライブラリの「 CreateDefault2 メソッド 」を参照してください。
スナップインの詳細については、MSDN ライブラリの 「WindowsPowerShell スナップインの作成方法 」と「about_PSSnapins」を参照してください。
Add-PSSnapin は、スナップインを現在のセッションにのみ追加します。 すべての Windows PowerShell セッションにスナップインを追加するには、それを Windows PowerShell プロファイルに追加します。 詳細については、「about_Profiles」を参照してください。
登録されている任意のスナップインは、Microsoft .NET Framework インストール ユーティリティを使用して追加できます。 詳細については、MSDN ライブラリの 「コマンドレット、プロバイダー、およびホスト アプリケーションを登録する方法 」を参照してください。
コンピューターに登録されているスナップインの一覧を取得するには、「
Get-PSSnapin -Registered」と入力します。スナップインを追加する前に、 Add-PSSnapin はスナップインのバージョンをチェックして、現在のバージョンの Windows PowerShell と互換性があることを確認します。 スナップインがバージョン チェックに失敗した場合、Windows PowerShell はエラーを報告します。