我在哪里可以找到PowerShell cmdlet到Object Class文档?

时间:2015-06-09 13:56:15

标签: .net powershell powershell-v2.0

我是PowerShell的新手,我有一个非常以Java为中心的开发背景。因此,我非常依赖于我正在使用的任何API的Javadoc。我现在正在尝试编写一些比仅仅简单的脚本更强大的PowerShell代码。我想使用Try / Catch / Finally,例如,捕获错误并处理它们。但是,我不想抓住基础[system.exception]类。

在Javadoc中,如果一个动作抛出异常,我可以在Javadoc中非常清楚地看到异常是什么,并抓住它(在可能抛出几个异常的情况下,我想做不同的事情取决于哪个一个是例如)。

我正在寻找PowerShell的类似文档。例如,

New-Item F:\ExistingFolder\NewFolder -Type Directory
如果NewFolder已经存在,

会抛出异常。如果ExistingFolder不存在,它也可能抛出不同的异常。

如果可以的话,有人可以指点我这样的文件吗?

1 个答案:

答案 0 :(得分:1)

您必须找出用于完成工作并查看其文档的基础dotnet方法。如果您的示例可能是CreateDirectory方法:

Exception                    Condition

IOException                  The directory specified by path is a file.
                             -or-
                             The network name is not known.

UnauthorizedAccessException  The caller does not have the required permission.

ArgumentException            path is a zero-length string, contains only white space,
                             or contains one or more invalid characters. You can query
                             for invalid characters by using the GetInvalidPathChars
                             method.
                             -or-
                             path is prefixed with, or contains, only a colon character
                             (:).

ArgumentNullException        path is null.

PathTooLongException         The specified path, file name, or both exceed the system-
                             defined maximum length. For example, on Windows-based
                             platforms, paths must be less than 248 characters and
                             file names must be less than 260 characters.

DirectoryNotFoundException   The specified path is invalid (for example, it is on an
                             unmapped drive).

NotSupportedException        path contains a colon character (:) that is not part of
                             a drive label ("C:\").

我不知道引用PowerShell cmdlet调用的dotnet方法的官方(或非官方)文档。