@ -29,6 +29,9 @@ Function Get-MachineSid {
# only accessible by the Local System account. This method get's the local
# only accessible by the Local System account. This method get's the local
# admin account (ends with -500) and lops it off to get the machine sid.
# admin account (ends with -500) and lops it off to get the machine sid.
$machine_sid = $null
try {
$admins_sid = " S-1-5-32-544 "
$admins_sid = " S-1-5-32-544 "
$admin_group = ( [ Security.Principal.SecurityIdentifier ] $admins_sid ) . Translate ( [ Security.Principal.NTAccount ] ) . Value
$admin_group = ( [ Security.Principal.SecurityIdentifier ] $admins_sid ) . Translate ( [ Security.Principal.NTAccount ] ) . Value
@ -38,7 +41,6 @@ Function Get-MachineSid {
$searcher = New-Object -TypeName System . DirectoryServices . AccountManagement . PrincipalSearcher ( $group_principal )
$searcher = New-Object -TypeName System . DirectoryServices . AccountManagement . PrincipalSearcher ( $group_principal )
$groups = $searcher . FindOne ( )
$groups = $searcher . FindOne ( )
$machine_sid = $null
foreach ( $user in $groups . Members ) {
foreach ( $user in $groups . Members ) {
$user_sid = $user . Sid
$user_sid = $user . Sid
if ( $user_sid . Value . EndsWith ( " -500 " ) ) {
if ( $user_sid . Value . EndsWith ( " -500 " ) ) {
@ -46,6 +48,10 @@ Function Get-MachineSid {
break
break
}
}
}
}
} catch {
#can fail for any number of reasons, if it does just return the original null
Add-Warning -obj $result -message " Error during machine sid retrieval: $( $_ . Exception . Message ) "
}
return $machine_sid
return $machine_sid
}
}