Afr*_*roz 5 windows powershell
我试图找到一个在服务器上卸载程序的用户.这是我正在使用的脚本和结果.从事件查看器,我能够看到用户,但看起来像Get-WinEvent返回UserId但没有用户名.有没有办法从Get-WinEvent返回事件1034的用户名?
Get-WinEvent -FilterHashtable @{LogName='Application'; Id=1034} -MaxEvents 1 | format-list
Run Code Online (Sandbox Code Playgroud)
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.
Run Code Online (Sandbox Code Playgroud)
使用.NET的SecurityIdentifier,如此处所述.
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;
}
Run Code Online (Sandbox Code Playgroud)
对于非空用户ID,我能够成功识别用户名.
| 归档时间: |
|
| 查看次数: |
4277 次 |
| 最近记录: |