Catchコマンドに問題があります。PowerShellでのキャッチに関する問題
Try
{
Add-Computer -DomainName "MyDomain.Dom" -Credential $DomainCred -PassThru -ErrorAction Stop
}
Catch [System.InvalidOperationException]
{
"Your Computer Is Unable To Contact The Domain"
}
私はキャッチに何かを得ていないのです。このかかわらを実行するたびに:私はプロセスにしようとしている次のスクリプトを持っています。ここで私がスクリプトから得るエラーが報告されています:
PSMessageDetails :
Exception : System.InvalidOperationException: This command cannot be executed on target computer('') due to following error: The specified domain either does not exist or could not
be contacted.
TargetObject :
CategoryInfo : InvalidOperation: (MYPC:String) [Add-Computer], InvalidOperationException
FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.AddComputerCommand
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
PipelineIterationInfo : {0, 1}
アイデアはありますか?
作業溶液(その組み合わせの貢献のためのPKとパトリックのおかげで)
Try
{
Add-Computer -DomainName "MyDomain.Dom" -Credential $DomainCred -PassThru -ErrorAction Stop
}
Catch [System.Management.Automation.RuntimeException]
{
"Your Computer Is Unable To Contact The Domain"
}
応答をありがとう、私はSystem.Management.Automation.RuntimeExceptionに置き換えましたが、私はまだ同じ問題があります。私はエラーを取り除き、キャッチだけを使ってみましたが、問題は解決しません。 –
キャッチブロックにはまったく入ることはできませんか?これを試してみて、出力が何であるかを教えてください:試してみてください { \tスロー } キャッチ { \t $ _ Exception.GetType()|。 FullName を選択してください} –