Repository navigation
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
In PS 5.1 I can use this line of code:
$Pipe.GetAccessControl().access
to obtain this output:
PipeAccessRights : ReadWrite, Synchronize
AccessControlType : Allow
IdentityReference : <username>
IsInherited : False
InheritanceFlags : None
PropagationFlags : None
On V5 you use: [IO.Pipes.NamedPipeServerStream]::new
on V7 you use : [IO.Pipes.NamedPipeServerStreamacl]::Create
To create the access rules
$ps = [IO.Pipes.PipeSecurity]::new() $ar = @() $ar += [IO.Pipes.PipeAccessRule]::new($UserAccessName,'ReadWrite', 'Allow') foreach ($Item in $ar) {$ps.AddAccessRule($Item)} $ps
I know in V7 the rule works as I am denied access if the 'Allow' is changed to 'Deny' but I cannot work out how to obtain the access rights to check them on PS V7 Any help appreciated.
[psobject](Get-ChildItem -Path ('\.\pipe{0}' -f $Pipename)
does not appear to provide an answer that I can see.
Expected behavior
N/AActual behavior
N/AError details
N/AEnvironment data
Name Value
---- -----
PSVersion 5.1.19041.4522
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.4522
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Name Value
---- -----
PSVersion 7.4.2
PSEdition Core
GitCommitId 7.4.2
OS Microsoft Windows 10.0.19045
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Name Value
---- -----
PSVersion 7.5.0-preview.3
PSEdition Core
GitCommitId 7.5.0-preview.3
OS Microsoft Windows 10.0.19045
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0Visuals
N/A
Activity
jborean93 commentedon Jun 18, 2024
As .NET is cross platform a lot of the Windows specific components like security descriptors were moved to extension methods through a separate assembly. In C# this mostly just works transparently as you can call them directly on the instance and the compiler will work in the background to call the extension method. In PowerShell this is not the case so you'll have to call the static extension method directly.
For named pipes all the SD based methods are now in NamedPipeServerStreamAcl (to create a pipe with an explicit SD) and PipesAclExtensions (to get and set an SD on a pipe). So in PowerShell the code to get and set the SD on a
PipeStreamobject would beThe same thing also applies to files where the
GetAccessControlandSetAccessControlare no longer part of the base class implementation but part of an extension method, this time FileSystemAclExtensions. So if you have a file object that returned fromGet-Item/Get-ChildItemyou would doUnfortunately PowerShell cannot automatically paper over extension methods like the C# compiler has so you'll need to explicitly call them. This means using
ifstatements to have a path when running 5.1 and 7.x if you need your script to run on both.RG255 commentedon Jun 18, 2024
Thank you for the information. I will make the changes tomorrow and then close off the case.
RG255 commentedon Jun 19, 2024
Yes that is exactly what I wanted - Issue closed
Note: you also need to include:
#requires -Modules Microsoft.PowerShell.Securitymicrosoft-github-policy-service commentedon Jun 19, 2024
📣 Hey RG255, how did we do? We would love to hear your feedback with the link below! 🗣️
🔗 https://aka.ms/PSRepoFeedback