2019-10-17 16:51:12 -04:00
|
|
|
function Get-IcingaUserSID()
|
|
|
|
|
{
|
|
|
|
|
param(
|
|
|
|
|
[string]$User
|
|
|
|
|
);
|
|
|
|
|
|
2020-03-11 08:01:54 -04:00
|
|
|
if ($User -eq 'LocalSystem') {
|
|
|
|
|
$User = 'NT Authority\SYSTEM';
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-18 04:45:22 -05:00
|
|
|
$UserData = Split-IcingaUserDomain -User $User;
|
2019-10-17 16:51:12 -04:00
|
|
|
|
|
|
|
|
try {
|
2020-11-18 04:45:22 -05:00
|
|
|
$NTUser = New-Object System.Security.Principal.NTAccount($UserData.Domain, $UserData.User);
|
2019-10-17 16:51:12 -04:00
|
|
|
$SecurityData = $NTUser.Translate([System.Security.Principal.SecurityIdentifier]);
|
|
|
|
|
} catch {
|
|
|
|
|
throw $_.Exception;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($null -eq $SecurityData) {
|
|
|
|
|
throw 'Failed to fetch user information from system';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $SecurityData.Value;
|
|
|
|
|
}
|