Can someone please try to explain this very odd behaviour
Posted: Fri Nov 10, 2017 12:07 am
All,
I not seen the following before and wandrered if anyone eles had run into it
I am using PowerShell 5.1.14393.1480
if I fun the following code in the PowerShell console (Start > Run > PowerShell) it returns an answer of 'Authorised' as I am indeed a member of an AD group whose SID is S-1-5-21-3674026133-984544165-2712361304-145687 however when I run the exact same code from an IDE (I have tried PowerShell Studio, PowerGIU and PowerShell ISE) that all some up with the oposite answer 'NotAuthorised' why? to test simply look at an AD group you are a member of note the SID and replace the SID in the script with the one for your group.
function Check-UserIsAuthorised {
[cmdletbinding()]
param($AuthorisedGroupSID)
$X = @([System.Security.Principal.WindowsIdentity]::GetCurrent().Groups | Select-Object -ExpandProperty value)
if ($X -contains "S-1-5-21-3674026133-984544165-2712361304-145687") {
write-verbose "Authorised"
return "Authorised"
}
else {
Write-Verbose "NotAuthorised"
return "NotAuthorised"
}
}
Check-UserIsAuthorised
I not seen the following before and wandrered if anyone eles had run into it
I am using PowerShell 5.1.14393.1480
if I fun the following code in the PowerShell console (Start > Run > PowerShell) it returns an answer of 'Authorised' as I am indeed a member of an AD group whose SID is S-1-5-21-3674026133-984544165-2712361304-145687 however when I run the exact same code from an IDE (I have tried PowerShell Studio, PowerGIU and PowerShell ISE) that all some up with the oposite answer 'NotAuthorised' why? to test simply look at an AD group you are a member of note the SID and replace the SID in the script with the one for your group.
function Check-UserIsAuthorised {
[cmdletbinding()]
param($AuthorisedGroupSID)
$X = @([System.Security.Principal.WindowsIdentity]::GetCurrent().Groups | Select-Object -ExpandProperty value)
if ($X -contains "S-1-5-21-3674026133-984544165-2712361304-145687") {
write-verbose "Authorised"
return "Authorised"
}
else {
Write-Verbose "NotAuthorised"
return "NotAuthorised"
}
}
Check-UserIsAuthorised