Forum Discussion
powershell create a catalog file
- Jun 03, 2020
Hi William,
I don’t know why you want it like this but it is possible. In the snippet below you’ll find a way to do this.
$Path = "c:\temp" $Outputfile = "c:\temp\output.txt" $allitems = Get-ChildItem -path $Path -Recurse $groups = $allitems | Group-Object -Property PSParentPath $lines = @() foreach($group in $groups){ $lines += $group.name.replace("Microsoft.PowerShell.Core\FileSystem::", "----") + "----" $items = $group.Group foreach($item in $items){ if(-NOT $item.PSIsContainer){ $lines += $item.name } } } $lines | out-file -FilePath $Outputfile
It’s also possible to export to data to a XML file for later analysis (in powershell). You can import this data later (also on a different device). You will keep all properties like size (Length), dates (Create, LastAccessTime, LastWritetime etc) and many more. Disadvantage is that the output XML file is bigger. See the snippet below:
# Get and export data $allitems = Get-ChildItem -path $Path -Recurse $allitems | Export-Clixml "c:\temp\output.xml" # Import data $importedItems = Import-Clixml "c:\temp\output.xml"
I hope it works out for you William!
Good luck!
Grtz, Manfred de Laat
Hi William,
I don’t know why you want it like this but it is possible. In the snippet below you’ll find a way to do this.
$Path = "c:\temp"
$Outputfile = "c:\temp\output.txt"
$allitems = Get-ChildItem -path $Path -Recurse
$groups = $allitems | Group-Object -Property PSParentPath
$lines = @()
foreach($group in $groups){
$lines += $group.name.replace("Microsoft.PowerShell.Core\FileSystem::", "----") + "----"
$items = $group.Group
foreach($item in $items){
if(-NOT $item.PSIsContainer){
$lines += $item.name
}
}
}
$lines | out-file -FilePath $Outputfile
It’s also possible to export to data to a XML file for later analysis (in powershell). You can import this data later (also on a different device). You will keep all properties like size (Length), dates (Create, LastAccessTime, LastWritetime etc) and many more. Disadvantage is that the output XML file is bigger. See the snippet below:
# Get and export data
$allitems = Get-ChildItem -path $Path -Recurse
$allitems | Export-Clixml "c:\temp\output.xml"
# Import data
$importedItems = Import-Clixml "c:\temp\output.xml"
I hope it works out for you William!
Good luck!
Grtz, Manfred de Laat
Manfred101 Thanks sooooo much!
It works as expected. Now a couple of enhancements as below:
1) Can we ignore the path, only folder display
2) Can we ignore the parent folder, in this case is temp folder in your code, only subfolders under temp
3) Can we comment out certain file with certain extension, i.e, *.txt file will be comment out with ;
Thanks again for your help!!