2016-04-25 72 views
1
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 

上面的代碼給我的文本文件在不同的文件夾,但我也想補充的最後修改日期和時間..謝謝我想上次修改的日期和時間添加到此PowerShell腳本

+0

可以公開屬性/什麼獲取-ChildItem以「get-childitem返回方法|獲取member' –

回答

1

這將做到這一點:

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 
+0

我說這和它的工作,我能達到我想要的。 – HushMamba

1

試試這個。你可以刪除行你不想

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 
+0

雖然這可以做到;它增加了更多的細節, – HushMamba

相關問題