7

別の場所 (C# アプリケーション、Web サービスなど) から powershellscript を実行すると問題が発生します。これはユーザー コンテキストの問題だと思うので、どのユーザー コンテキストで powershell スクリプトが実行されているかを調べようとしています。

powershellscript の現在のユーザーコンテキストをログに記録する可能性はありますか?

4

2 に答える 2

11

WindowsIdentity クラスを使用して、現在のスレッド ユーザーを取得できます。

[Security.Principal.WindowsIdentity]::GetCurrent()
于 2012-06-20T08:43:15.067 に答える
5

実際のユーザーを知る必要がある場合:

[reflection.assembly]::LoadWithPartialName("System.DirectoryServices.AccountManagement")
[System.DirectoryServices.AccountManagement.UserPrincipal]::Current

使用する:

[System.DirectoryServices.AccountManagement.UserPrincipal]::Current | gm

の利用可能なプロパティ/メソッドを知る UserPrincipal

于 2012-06-20T08:44:15.657 に答える