2019-10-17 16:51:12 -04:00
|
|
|
function Get-IcingaUserSID()
|
|
|
|
|
{
|
|
|
|
|
param(
|
|
|
|
|
[string]$User
|
|
|
|
|
);
|
|
|
|
|
|
2021-08-06 12:12:27 -04:00
|
|
|
if ([string]::IsNullOrEmpty($User)) {
|
|
|
|
|
return $null;
|
|
|
|
|
}
|
|
|
|
|
|
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 {
|
2021-08-06 12:12:27 -04:00
|
|
|
try {
|
|
|
|
|
# Try again but this time with our domain
|
|
|
|
|
$UserData.Domain = (Get-IcingaWindowsInformation -ClassName Win32_ComputerSystem).Domain;
|
|
|
|
|
$NTUser = New-Object System.Security.Principal.NTAccount($UserData.Domain, $UserData.User);
|
|
|
|
|
$SecurityData = $NTUser.Translate([System.Security.Principal.SecurityIdentifier]);
|
|
|
|
|
} catch {
|
|
|
|
|
throw $_.Exception;
|
|
|
|
|
}
|
2019-10-17 16:51:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($null -eq $SecurityData) {
|
|
|
|
|
throw 'Failed to fetch user information from system';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $SecurityData.Value;
|
|
|
|
|
}
|