Root Loop
Root Loop

Reputation: 3162

Powershell won't output folder path?

When I filter some folders and output to a html file, the path in the result is always empty. I can't find why it only works on files but folders?

Get-ChildItem -Recurse $source -Filter *PML_*_ECR* | where { $_.psiscontainer } | Where{$_.LastWriteTime -gt (Get-Date).AddDays(-6)} | sort LastWriteTime -descending | select name,LastWriteTime,Directory | convertto-html -head $a -body "<H2>Folder LIST FOR PAST 7 DAYS </H2>" | out-file $output\results.htm

Upvotes: 0

Views: 93

Answers (2)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200293

Folders are represented as DirectoryInfo objects, which don't have a Directory property. The full path of the folder object itself is provided via the FullName property:

... | select Name, LastWriteTime, FullName | ...

The path of the parent folder can be obtained via the Parent property:

... | select Name, LastWriteTime, @{n='Directory';e={$_.Parent.FullName}} | ...

Upvotes: 2

TheMadTechnician
TheMadTechnician

Reputation: 36297

Because Directory is not a property of that object. Try doing:

Get-ChildItem -Recurse $source -Filter *PML_*_ECR* | where { $_.psiscontainer } ||GM

Then look at the available properties. I think FullName may better suite your needs.

Upvotes: 0

Related Questions