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

Posted on 2014-07-11
Last Modified: 2014-07-17
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?
Question by:rye004
    LVL 4

    Expert Comment

    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

    Author Comment

    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.
    LVL 4

    Accepted Solution

    something like this?
    Get-ChildItem -Recurse -ErrorAction SilentlyContinue |select fullname, @{"N"='Owner';"E"={(get-acl |select owner).owner}}

    Open in new window

    LVL 4

    Expert Comment

    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 ;-)

    Author Closing Comment

    Thank you for your help.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Why would I want to create a function for tracking messages? I am glad you asked. As with most monotonous/routine tasks, human error tends to creep in after doing the same task over and over again. By creating a function, you load the function once…
    Are you one of those front-line IT Service Desk staff fielding calls, replying to emails, all-the-while working to resolve end-user technological nightmares? I am! That's why I have put together this brief overview of tools and techniques I use in o…
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now