Owner of folders/Files

Created an script to get the owner of files and folders but it displays the short ID set up in AD and i would like to get the full name, would be it possible?

Also get the last modified date but is blank for all the files and folders even if i renamed and updated a file

Is it possible to get as well the File latest modifier name

this is what im using

Get-ChildItem "path" -force -Recurse | Select Name,Directory,@{Name="Owner";Expression={(Get-ACL $_.Fullname).Owner}},CreationTime,lastModifiedTime,LastAccessTime

Name : test.docx
Directory : path
Owner : shortID
CreationTime : 3/28/2020 3:18:42 PM
lastModifiedTime :
LastAccessTime : 3/28/2020 3:23:57 PM

Parents
No Data
Reply
  • You can only get what the OS provides. Using PowerShell or not. 

    To see all the properties and values of an object, this is what the Get-Member cmdlet is used for.

    Select only 1 folder and pipe that to Get-Member.

    Get-ChildItem -Path 'D:\Temp' -Directory | 
    Select-Object -First 1 | 
    Get-Member -MemberType Properties 
    <#
    # Results
    
       TypeName: System.IO.DirectoryInfo
    
    Name              MemberType     Definition
    ----              ----------     ----------
    LinkType          CodeProperty   System.String LinkType{get=GetLinkType;}
    Mode              CodeProperty   System.String Mode{get=Mode;}
    Target            CodeProperty   System.Collections.Generic.IEnumerable`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] Target{g...
    PSChildName       NoteProperty   string PSChildName=AddressFiles
    PSDrive           NoteProperty   PSDriveInfo PSDrive=D
    PSIsContainer     NoteProperty   bool PSIsContainer=True
    PSParentPath      NoteProperty   string PSParentPath=Microsoft.PowerShell.Core\FileSystem::D:\Temp
    PSPath            NoteProperty   string PSPath=Microsoft.PowerShell.Core\FileSystem::D:\Temp\AddressFiles
    PSProvider        NoteProperty   ProviderInfo PSProvider=Microsoft.PowerShell.Core\FileSystem
    Attributes        Property       System.IO.FileAttributes Attributes {get;set;}
    CreationTime      Property       datetime CreationTime {get;set;}
    CreationTimeUtc   Property       datetime CreationTimeUtc {get;set;}
    Exists            Property       bool Exists {get;}
    Extension         Property       string Extension {get;}
    FullName          Property       string FullName {get;}
    LastAccessTime    Property       datetime LastAccessTime {get;set;}
    LastAccessTimeUtc Property       datetime LastAccessTimeUtc {get;set;}
    LastWriteTime     Property       datetime LastWriteTime {get;set;}
    LastWriteTimeUtc  Property       datetime LastWriteTimeUtc {get;set;}
    Name              Property       string Name {get;}
    Parent            Property       System.IO.DirectoryInfo Parent {get;}
    Root              Property       System.IO.DirectoryInfo Root {get;}
    BaseName          ScriptProperty System.Object BaseName {get=$this.Name;}
    #>
    

    To see all on an object use the -Force switch

    Get-ChildItem -Path 'D:\Temp' -Directory | 
    Select-Object -First 1 | 
    Get-Member -Force

    Adding in your the ACL use case

    Get-ChildItem -Path 'D:\Temp' -Directory | 
    Select-Object -First 1 | 
    Get-ACL | 
    Get-Member -MemberType Properties      
    <#
    # Results
    
       TypeName: System.Security.AccessControl.DirectorySecurity
    
    Name                    MemberType     Definition
    ----                    ----------     ----------
    Access                  CodeProperty   System.Security.AccessControl.AuthorizationRuleCollection Access{get=GetAccess;}
    CentralAccessPolicyId   CodeProperty   System.Security.Principal.SecurityIdentifier CentralAccessPolicyId{get=GetCentralAccessPolicyId;}
    CentralAccessPolicyName CodeProperty   System.String CentralAccessPolicyName{get=GetCentralAccessPolicyName;}
    Group                   CodeProperty   System.String Group{get=GetGroup;}
    Owner                   CodeProperty   System.String Owner{get=GetOwner;}
    Path                    CodeProperty   System.String Path{get=GetPath;}
    Sddl                    CodeProperty   System.String Sddl{get=GetSddl;}
    PSChildName             NoteProperty   string PSChildName=AddressFiles
    PSDrive                 NoteProperty   PSDriveInfo PSDrive=D
    PSParentPath            NoteProperty   string PSParentPath=Microsoft.PowerShell.Core\FileSystem::D:\Temp
    PSPath                  NoteProperty   string PSPath=Microsoft.PowerShell.Core\FileSystem::D:\Temp\AddressFiles
    PSProvider              NoteProperty   ProviderInfo PSProvider=Microsoft.PowerShell.Core\FileSystem
    AccessRightType         Property       type AccessRightType {get;}
    AccessRuleType          Property       type AccessRuleType {get;}
    AreAccessRulesCanonical Property       bool AreAccessRulesCanonical {get;}
    AreAccessRulesProtected Property       bool AreAccessRulesProtected {get;}
    AreAuditRulesCanonical  Property       bool AreAuditRulesCanonical {get;}
    AreAuditRulesProtected  Property       bool AreAuditRulesProtected {get;}
    AuditRuleType           Property       type AuditRuleType {get;}
    AccessToString          ScriptProperty System.Object AccessToString {get=$toString = "";...
    AuditToString           ScriptProperty System.Object AuditToString {get=$toString = "";...
    #>

    So, the above is all that is available in context. So, this when looking at a directory...


    Get-ChildItem -Path 'D:\Temp' -Directory | 
    Select-Object -First 1 | 
    Select '*', 
    @{
        Name       = 'Owner'
        Expression = {
                        Get-ACL | 
                        Select-Object -ExpandProperty Owner
                     }
    }
    <#
    # Results
    
    PSPath            : Microsoft.PowerShell.Core\FileSystem::D:\Temp\AddressFiles
    PSParentPath      : Microsoft.PowerShell.Core\FileSystem::D:\Temp
    PSChildName       : AddressFiles
    PSDrive           : D
    PSProvider        : Microsoft.PowerShell.Core\FileSystem
    PSIsContainer     : True
    Mode              : d-----
    BaseName          : AddressFiles
    Target            : {}
    LinkType          : 
    Name              : AddressFiles
    FullName          : D:\Temp\AddressFiles
    Parent            : Temp
    Exists            : True
    Root              : D:\
    Extension         : 
    CreationTime      : 17-Mar-20 23:46:03
    CreationTimeUtc   : 18-Mar-20 06:46:03
    LastAccessTime    : 17-Mar-20 23:48:15
    LastAccessTimeUtc : 18-Mar-20 06:48:15
    LastWriteTime     : 17-Mar-20 23:48:15
    LastWriteTimeUtc  : 18-Mar-20 06:48:15
    Attributes        : Directory
    Owner             : (The full SID will show here, but I am not showing mine for obvious reasons.)
    #>

    ... and this when looking at a file.

    Get-ChildItem -Path 'D:\Temp' -File | 
    Select-Object -First 1 | 
    Select '*', 
    @{
        Name       = 'Owner'
        Expression = {
                        Get-ACL | 
                        Select-Object -ExpandProperty Owner
                     }
    }
    <#
    # Results
    
    PSPath            : Microsoft.PowerShell.Core\FileSystem::D:\Temp\23694d1213305764-revision-number-in-excel-book1.xls
    PSParentPath      : Microsoft.PowerShell.Core\FileSystem::D:\Temp
    PSChildName       : 23694d1213305764-revision-number-in-excel-book1.xls
    PSDrive           : D
    PSProvider        : Microsoft.PowerShell.Core\FileSystem
    PSIsContainer     : False
    Mode              : -a----
    VersionInfo       : File:             D:\Temp\23694d1213305764-revision-number-in-excel-book1.xls
                        InternalName:     
                        OriginalFilename: 
                        FileVersion:      
                        FileDescription:  
                        Product:          
                        ProductVersion:   
                        Debug:            False
                        Patched:          False
                        PreRelease:       False
                        PrivateBuild:     False
                        SpecialBuild:     False
                        Language:         
                        
    BaseName          : 23694d1213305764-revision-number-in-excel-book1
    Target            : {}
    LinkType          : 
    Name              : 23694d1213305764-revision-number-in-excel-book1.xls
    Length            : 28817
    DirectoryName     : D:\Temp
    Directory         : D:\Temp
    IsReadOnly        : False
    Exists            : True
    FullName          : D:\Temp\23694d1213305764-revision-number-in-excel-book1.xls
    Extension         : .xls
    CreationTime      : 06-Feb-20 14:44:06
    CreationTimeUtc   : 06-Feb-20 22:44:06
    LastAccessTime    : 06-Feb-20 14:44:06
    LastAccessTimeUtc : 06-Feb-20 22:44:06
    LastWriteTime     : 06-Feb-20 14:02:47
    LastWriteTimeUtc  : 06-Feb-20 22:02:47
    Attributes        : Archive
    Owner             : (The full SID will show here, but I am not showing mine for obvious reasons.)
    #>

    Of course, you can do both at the same time. Yet notice in each case there is no 'lastModifiedTime', property to retrieve. It's 'LastWriteTime'. A modification of a file/folder is a write.

Children
No Data