Please … no flames … I really do need to update PowerShell 2 code for legacy air gapped XP systems.
I have this simple example.
$Folder = 'C:\Some\Folder'
$ACL = Get-Acl -Path $Folder -Audit
This works peachy in both PS2 and beyond.
However, I need the audit flags. This works fine in PowerShell 5.1 and beyond
$ACL.Audit.AuditFlags
PS C:\> $ACL.Audit.AuditFlags
Success, Failure
PS C:\>
This does not work in PowerShell 2. I can see the properties exist as such:
PS C:\> $ACL.Audit
FileSystemRights : ExecuteFile, DeleteSubdirectoriesAndFiles, Write, Delete, ReadPermissions, ChangePermissions, TakeO
wnership
AuditFlags : Success, Failure
IdentityReference : Everyone
IsInherited : False
InheritanceFlags : ContainerInherit, ObjectInherit
PropagationFlags : None
However, when I attempt the same syntax as such, it returns nothing:
PS C:\> $ACL.Audit.AuditFlags
PS C:\>
I can however get the values with another method:
$ACL.Audit | Select-Object -ExpandProperty 'AuditFlags'
PS C:\> $ACL.Audit | Select-Object -ExpandProperty 'AuditFlags'
Success, Failure
PS C:\>
Is this simply a limitation to PS2 and I need to use the longer syntax? I need pretty much all the properties from $ACL.Audit and would prefer to use the shorter dotted notation if possible. I should point out I have only tested on PS2, 5.1 and 7.3 and nothing in between.
Thanks in advance for any help.