Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 226
  • Last Modified:

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?
0
rye004
Asked:
rye004
  • 3
  • 2
1 Solution
 
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
0
 
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.
0
 
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

0
 
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 ;-)
0
 
rye004Author Commented:
Thank you for your help.
0

Featured Post

Who's Defending Your Organization from Threats?

Protecting against advanced threats requires an IT dream team – a well-oiled machine of people and solutions working together to defend your organization. Download our resource kit today to learn more about the tools you need to build you IT Dream Team!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now