我有一个不断抛出此错误的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
是否有一种简单的方法可以在运行之前测试是否支持cmdlet?我知道我可以尝试捕获cmdlet,但与简单的检查相比,这种方法看起来相当昂贵。
由于
答案 0 :(得分:1)
您可以轻松检查会话中是否有cmdlet(使用Get-Command),但是没有直接的方法来测试可用的cmdlet是否支持当前的操作系统。此cmdlet的帮助说明部分说:
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.
但是我不会依赖于Notes的准确性。我能想到的最好的就是你的建议,使用try / catch。