I am using this code as a means of validating a user or group in advance of setting permissions on a folder and in that aspect it works great.
However, somehow the If
is returning a 0. If I remove out the If
I don't get a 0 echo to console. If I just rem out the add within the if I still get the 0. So it's definitely something in the if. But I have never seen any info returned like this when part of the If.
try {
if (-not ((New-Object System.Security.Principal.NTAccount($principal)).Translate([System.Security.Principal.SecurityIdentifier]))) {
$filePermissions.error.Add("'$principal' is not a valid user or group")
}
} catch {
$filePermissions.error.Add("'$principal' is not a valid user or group")
}
I also tried adding some > $nulls in the if, like this
if (-not ((New-Object System.Security.Principal.NTAccount($principal) > $null).Translate([System.Security.Principal.SecurityIdentifier]) > $null)) {
and I still see the 0. Obviously something fundamental is happening, related to New-Object I suspect, but I am really not understanding it.