Question

I am trying to convert my batch file syntax to PowerShell v3.0. I need to pull all the file names from a mapped network drive and save it to a folder on my root C:

Everything works except when it comes to saving the file names. If I do

dir /s > C:\2\filename.txt

In a batch file it will output the file's name (along with the extension) and the date modified to a .txt file. However I cannot get the PowerShell v3.0 equvalent to work. It just creates a txt file but nothing is saved within the file. Here is my PowerShell v3.0 code.

Get-ChildItem -Path K:\Transactions\Processed\Audit-Images\Lane` 12\$date\done > C:\2\$date-LaneServer12ImagesDONE.txt
Était-ce utile?

La solution

In the examples below, you may want to add some parameters to Get-ChildItem depending on what you're looking for. "-Force" to have it list hidden files, "-Attributes !Directory" to exclude directory names.

I would find the output most useful in a csv.

Get-ChildItem -Path K:\Transactions\Processed\Audit-Images\Lane` 12\$date\done -Recurse | Select-Object Name,LastWriteTime | Export-CSV "C:\2\filename.csv"

Same line, in a text file:

Get-ChildItem -Path K:\Transactions\Processed\Audit-Images\Lane` 12\$date\done -Recurse | Select-Object @{n='File';e={$_.Name + " " + $_.LastWriteTime}} | Out-File "C:\2\filename.txt"
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top