1

このエラーをスローし続けるPowerShellスクリプトがあります

Get-ComputerRestorePoint : This functionality is not supported on this operating system.
At line:1 char:25
+ Get-ComputerRestorePoint <<<<
    + CategoryInfo          : InvalidOperation: (:) [Get-ComputerRestorePoint], ArgumentException
    + FullyQualifiedErrorId : GetComputerRestorePointNotSupported,Microsoft.PowerShell.Commands.GetComputerRestorePoin
   tCommand

コマンドレットを実行する前に、コマンドレットがサポートされているかどうかをテストする簡単な方法はありますか?コマンドレットの周りにtrycatchをスローできることは知っていますが、このアプローチは単純なチェックに比べてかなりコストがかかるようです。

ありがとう

4

1 に答える 1

1

(Get-Command を使用して) セッションでコマンドレットが使用可能かどうかを簡単に確認できますが、使用可能なコマンドレットが現在の OS をサポートしているかどうかを直接テストする方法はありません。このコマンドレットのヘルプ ノート セクションには、次のように記載されています。

NOTES

        To run a Get-ComputerRestorePoint command on Windows Vista and later versions 
        of Windows, open Windows PowerShell with the "Run as administrator" option.

        This cmdlet uses the Windows Management Instrumentation (WMI) SystemRestore 
        class.

ただし、メモが正確であるとは限りません。私が考えることができる最善のことは、あなたが提案するものです.try/catchを使用してください.

于 2013-01-08T22:44:12.720 に答える