Insert value from pipeline to declare .NET class

Is there is way to use a value from the pipeline to declare a .NET Class? this is what I tried, but it’s not working:

[System.Security.AccessControl.FileSystemAccessRule].GetProperties().Name | ForEach-Object {
    Write-Host "$_ values are:"
    [System.Security.AccessControl.$_]
    [System.Security.AccessControl.$($_)]
}

Edit: Corrected .Net class being used.

Hello,

What is the requirement, and context?

Thank you.

It’s to let me know what values are in each property. It’s so I don’t need to look at the Microsoft doc and I have it ready at a moment’s notice.

I am not sure though, but you can get the properties of a given .Net class using the `Get-Member` CmdLet…

[pre]

[System.Security.AccessControl.FileSystemAccessRule] | Get-Member -MemberType *property

[/pre]

Also if .Net class is a type enum, then you can get the values using GetEnumNames() method

For example

# To check the .Net class is type Enum or not
[System.Windows.Forms.Appearance].IsEnum
# True

# To get the values
[System.Windows.Forms.Appearance].GetEnumNames()
# Normal
# Button

I was able to figure this out:

 

[System.Security.AccessControl.FileSystemAccessRule].GetProperties() | ForEach-Object {
    switch ($_.Name) {
        {("FileSystemRights PropagationFlags AccessControlType" -split " ") -eq $_} {
        Write-Host "value is $_ ----------------------------------------"
            Invoke-Expression -Command "[System.Security.AccessControl.$($_)].GetEnumNames()"
            Write-Host ""
        }

        InheritanceFlags {
        Write-Host "value is $_ ----------------------------------------"
            Invoke-Expression -Command "[System.Security.AccessControl.$($_)].GetEnumNames()"
            Write-Host ""
        }
    } 
}