mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-21 15:19:58 -05:00
35 lines
817 B
PowerShell
35 lines
817 B
PowerShell
function Get-IcingaUserSID()
|
|
{
|
|
param(
|
|
[string]$User
|
|
);
|
|
|
|
if ($User -eq 'LocalSystem') {
|
|
$User = 'NT Authority\SYSTEM';
|
|
}
|
|
|
|
[string]$Username = '';
|
|
[string]$Domain = '';
|
|
|
|
if ($User.Contains('\')) {
|
|
$TmpArray = $User.Split('\');
|
|
$Domain = $TmpArray[0];
|
|
$Username = $TmpArray[1];
|
|
} else {
|
|
$Domain = Get-IcingaNetbiosName;
|
|
$Username = $User;
|
|
}
|
|
|
|
try {
|
|
$NTUser = New-Object System.Security.Principal.NTAccount($Domain, $Username);
|
|
$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;
|
|
}
|