HushMamba
HushMamba

Reputation: 280

I want to add last modified date and time to this powershell script

Get-Childitem -path \\lettertext\BIZ -Recurse -Include *.txt |
ForEach-Object {
    $Parts = $_.fullname.split('\')[4..7]
    [PSCustomObject]@{
        Customer = $Parts[0]
        ClientGroup = $Parts[1]
        Client = $Parts[2]
        ClientDivision = $Parts[3]
        FileName = $_.FullName | Split-Path -Leaf


    }
} | Export-Csv c:\Letters\BIZ.csv -NoTypeInformation

The code above gives me the text files in the different folders but I want to also add the last modification date and time.. Thanks

Upvotes: 1

Views: 194

Answers (2)

Anthony Stringer
Anthony Stringer

Reputation: 2001

try this. you can remove the lines you don't want

Get-Childitem -path \\lettertext\BIZ -Recurse -Include *.txt |
ForEach-Object {
    $Parts = $_.fullname.split('\')[4..7]
    [PSCustomObject]@{
        Customer = $Parts[0]
        ClientGroup = $Parts[1]
        Client = $Parts[2]
        ClientDivision = $Parts[3]
        FileName = $_.name
        CreationTime = $_.CreationTime
        CreationTimeUtc = $_.CreationTimeUtc
        LastAccessTime = $_.LastAccessTime
        LastAccessTimeUtc = $_.LastAccessTimeUtc
        LastWriteTime = $_.LastWriteTime
        LastWriteTimeUtc = $_.LastWriteTimeUtc
    }
} | Export-Csv c:\Letters\BIZ.csv -NoTypeInformation

Upvotes: 1

HushMamba
HushMamba

Reputation: 280

This will do it:

Get-Childitem -path \\lettertext\BIZ -Recurse -Include *.txt |
ForEach-Object {
    $Parts = $_.fullname.split('\')[4..7]
    [PSCustomObject]@{
        Customer = $Parts[0]
        ClientGroup = $Parts[1]
        Client = $Parts[2]
        ClientDivision = $Parts[3]
        FileName =  $_.FullName | Split-Path -Leaf
        LastModifiedDate= $_.LastWriteTime  
        #| Split-Path -Leaf 


    }
} | Export-Csv c:\Letters\BIZ.csv -NoTypeInformation 

Upvotes: 1

Related Questions