0

呼び出しコマンドに関するエラー/例外の処理に問題があります。

ターゲットコンピューターが存在しないときにエラーをキャッチしようとしていますが、表示されるメッセージとキャッチブロックのスクリプトの動作方法から、見逃した、または理解できなかったことがあると思います。

これは、問題のあるスクリプトの部分です。

$session = New-Pssession -computername $computerName 
Invoke-Command -session $session -ScriptBlock $command -ArgumentList $sqlServerName, $userToGivePermisions          
Remove-PSsession -session $session

基本的$computerNameに、ネットワーク上の有効なコンピューターではないときにエラーを処理したいと考えています。テストするために意図的に間違った名前を付けたところ、次のエラーが発生しました。

[dcd] Connecting to remote server failed with the following error message : WinRM cannot process the request. The following error occured while using Kerberos authentication: The network path was not found.
Possible causes are:
-The user name or password specified are invalid.
-Kerberos is used when no authentication method and no user name are specified.
-Kerberos accepts domain user names, but not local user names.
-The Service Principal Name (SPN) for the remote computer name and port does not exist.
-The client and remote computers are in different domains and there is no trust between     the two domains.
After checking for the above issues, try the following:
-Check the Event Viewer for events related to authentication.
-Change the authentication method; add the destination computer to the WinRM  TrustedHosts configuration setting or use HTTPS transport.
Note that computers in the TrustedHosts list might not be authenticated.
-For more information about WinRM configuration, run the following command: winrm help config. For more information, see the about_Remote_Troubleshooting Help topic.
+ CategoryInfo          : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace)   [], PSRemotingTransportException
+ FullyQualifiedErrorId : PSSessionOpenFailed

[dcd] は存在しないマシンの名前です。コードを try catch に入れ、. を使用してエラー メッセージをチェックしました-contains。条件は常に偽であり、上記のエラーでほぼすべての単語を試しました。

を使用して catch ブロックにエラー メッセージを表示すると、$_.exception.message$session が null であるという別のエラーが発生しました。

$session に関する表示されたエラー メッセージで単語を使用し-containsても、テストしたすべての単語に対して false が返されました。

-containsこれらのどれがエラーなのか、なぜtrue が返されないのかわかりません。-ea stop終了しないエラーをすべてキャッチするために 3 行すべてに追加しましたが、役に立ちませんでした。

何が起こっているのか誰にも分かりますか?

4

1 に答える 1