windows - 从 Get-WinEvent 获取用户名

标签 windows powershell

我正在尝试查找在服务器上卸载程序的用户。这是我正在使用的脚本和结果。从事件查看器中,我能够看到用户,但看起来 Get-WinEvent 返回 UserId 但没有用户名。有没有办法从 Get-WinEvent 返回事件 1034 的用户名?

Get-WinEvent -FilterHashtable @{LogName='Application'; Id=1034} -MaxEvents 1 | format-list

TimeCreated  : 6/17/2013 1:41:27 PM
ProviderName : MsiInstaller
Id           : 1034
Message      : Windows Installer removed the product. Product Name: PAL. Product Version: 2.3.2. Product Language:
           1033. Manufacturer: PAL. Removal success or error status: 0.

最佳答案

使用 .NET 的 SecurityIdentifier , as described here .

Get-WinEvent -MaxEvents 1000 | foreach {
  $sid = $_.userid;
  if($sid -eq $null) { return; }
  $objSID = New-Object System.Security.Principal.SecurityIdentifier($sid);
  $objUser = $objSID.Translate([System.Security.Principal.NTAccount]);
  Write-Host $objUser.Value;
}

对于非空用户 ID,我能够成功识别用户名。

关于windows - 从 Get-WinEvent 获取用户名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17155311/

相关文章:

PowerShell计算错误

.net - 使用存储在变量中的类型进行 PowerShell 类型转换

azure - 使用 Powershell 获取应用服务计划的值(value)

windows - 具有多个实例的 Node.js Azure WorkerRole 无法使用同一端口?

windows - 如何使用 mingw 启用 tbb 安装 opencv

python - 在一个函数中强制将一个函数的语言环境设置为英国/英语,以便 datetime.strftime 始终返回英语格式

c++ - 编译后可执行文件出错

java - 段落条件嵌套正则表达式(递归)

powershell - 如何删除 Powershell 脚本本身正在使用的文件?

java - 在 Windows 操作系统中使用命令行查找与文件(.pdf)相关的默认程序的命令