How to use Power Shell to return the SID of a file

I am not new to a traditional command line, but am to Power Shell.  I am trying to write the full path of all files in a directory and sub directories and return the Active Directory SID.  Normally I would write something in C# to accomplish this.  Is this possible in Power Shell and if so how?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rastoiWindows DTS expertCommented:
What do you mean file AD SID? ACL?
Anycase, yes it is posible. Just precise your question i.e. with example of expected output for single file
rye004Author Commented:
Forgive me for the lack of detail.  By SID, I meant the System Identifier that is associated with a Windows Directory login.  When a file is created on an NTFS network share, the SID is kept with the file.  In the past I have used the following piece of code to determine the SID for a given file.  What this helps me do, is determine who originally made the file.  Is this the same as the ACL?

        static string getFileOwnerSid(string fileString)
            string returnString;

            var fs = File.GetAccessControl(fileString);

            var sid = fs.GetOwner(typeof(SecurityIdentifier));
            returnString = Convert.ToString(sid); // SID
            return returnString;
        } //getFileOwnerSid

Open in new window

What I would like to do is get a directory of all files in a given folder and sub-folders.  I would like to do this from a command line similar to using the DIR command.  It would be great if the output could show the SID and the full file path of the file for each row – each piece of information could be tab delimited.
I can easily write this in C# and make a command line.  However, I was wondering how difficult this would be using Power Shell.
rastoiWindows DTS expertCommented:
something like this?
Get-ChildItem -Recurse -ErrorAction SilentlyContinue |select fullname, @{"N"='Owner';"E"={(get-acl |select owner).owner}}

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rastoiWindows DTS expertCommented:
or, better as your vbs reffer to SID
Get-ChildItem -Recurse -ErrorAction SilentlyContinue |format-table fullname, @{"N"='Owner';"E"={(get-acl $_.fullname).GetOwner([System.Security.Principal.SecurityIdentifier])}} -wrap

Open in new window

not so difficult in powershell. biggest trouble is to choose/tune output for desired format ;-)
rye004Author Commented:
Thank you for your help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.