mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
36 lines
1 KiB
PowerShell
36 lines
1 KiB
PowerShell
function Get-IcingaUserSID()
|
|
{
|
|
param(
|
|
[string]$User
|
|
);
|
|
|
|
if ([string]::IsNullOrEmpty($User)) {
|
|
return $null;
|
|
}
|
|
|
|
if ($User -eq 'LocalSystem') {
|
|
$User = 'NT Authority\SYSTEM';
|
|
}
|
|
|
|
$UserData = Split-IcingaUserDomain -User $User;
|
|
|
|
try {
|
|
$NTUser = New-Object System.Security.Principal.NTAccount($UserData.Domain, $UserData.User);
|
|
$SecurityData = $NTUser.Translate([System.Security.Principal.SecurityIdentifier]);
|
|
} catch {
|
|
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 {
|
|
return $null;
|
|
}
|
|
}
|
|
|
|
if ($null -eq $SecurityData) {
|
|
return $null;
|
|
}
|
|
|
|
return $SecurityData.Value;
|
|
}
|