Powershell 将写主机输出重定向到新文件
Powershell redirect write-host output into new file
我正在尝试在执行命令后将 Powershell write-host
输出发送到新文件中,此命令创建一个空白文件
gci -r | % { Write-Host $_.Name,$_.FullName,$_.LastWriteTime } |ft -wrap | out-file output.txt
我想要 FileName
和 File Full Path
和 Last Write Time
在 输出文件这样
170801072740IMG-20170622-WA0012 (1).jpg O:0801072740IMG-20170622-WA0012 (1).jpg 1/14/2021 4:3
170801072756IMG-20170622-WA0014.jpg O:0801072756IMG-20170622-WA0014.jpg 1/14/2021 4:35:22 PM
170801072818IMG-20170624-WA0028.jpg O:0801072818IMG-20170624-WA0028.jpg 1/14/2021 4:35:22 PM
排除属性名称:
Mode LastWriteTime Length Name
---- ------------- ------ ----
还检查了另一个命令 Write-Output
gci -r | % { Write-Output $_.Name,$_.FullName,$_.LastWriteTime } >> output2.txt
此命令正在重定向输出,但输出格式不正确
输出文件:
Tuesday, March 9, 2021 1:14:42 AM
151104051548IMG_20151103_112015.jpg
O:1104051548IMG_20151103_112015.jpg
Friday, March 12, 2021 8:40:15 PM
151104051558IMG_20151103_123234.jpg
O:1104051558IMG_20151103_123234.jpg
Thursday, January 14, 2021 4:35:16 PM
151104051610IMG_20151103_123249.jpg
O:1104051610IMG_20151103_123249.jpg
Thursday, January 14, 2021 4:35:16 PM
我也尝试过 Start-Transcript
方法,但输出格式不正确
开始-转录输出文件
有什么办法可以解决这个问题吗?
gci -r -file | % { "$($_.Name) $($_.FullName) $($_.LastWriteTime)" >> G:\Test\Output.txt }
我添加了 -file 参数,因为不需要目录,因为它们包含在完整路径中。
示例输出:
Get-FileMetaDataReturnObject.ps1 G:\BEKDocs\Scripts\Functions\Get-FileMetaDataReturnObject.ps1 09/20/2018 20:03:57
Get-InstalledSoftware.ps1 G:\BEKDocs\Scripts\Functions\Get-InstalledSoftware.ps1 05/02/2020 12:24:47
Invoke-ExerciseTimer.ps1 G:\BEKDocs\Scripts\Functions\Invoke-ExerciseTimer.ps1 01/19/2017 15:01:49
New-Shortcut.txt G:\BEKDocs\Scripts\Functions\New-Shortcut.txt 01/15/2017 11:50:33
Test-RoboForm-Function.ps1 G:\BEKDocs\Scripts\Functions\Test-RoboForm-Function.ps1 02/24/2021 20:32:25
Get-DisabledServicesV1-00.ps1 G:\BEKDocs\Scripts\Get-DisabledServices\Get-DisabledServicesV1-00.ps1 01/13/2018 16:39:09
Get-DisabledServicesV2-00.ps1 G:\BEKDocs\Scripts\Get-DisabledServices\Get-DisabledServicesV2-00.ps1 01/14/2018 12:31:56
Get-WinVer-V-2-0.ps1 G:\BEKDocs\Scripts\Get-WinVer\Get-WinVer-V-2-0.ps1 03/12/2019 21:14:37
Get-WinVer-V-3-0.ps1 G:\BEKDocs\Scripts\Get-WinVer\Get-WinVer-V-3-0.ps1 12/10/2019 20:03:38
Get-WinVer-V-3-1.ps1 G:\BEKDocs\Scripts\Get-WinVer\Get-WinVer-V-3-1.ps1 12/11/2019 09:17:17
Get-WinVer-V-3-2.ps1 G:\BEKDocs\Scripts\Get-WinVer\Get-WinVer-V-3-2.ps1 01/15/2020 20:53:11
我正在尝试在执行命令后将 Powershell write-host
输出发送到新文件中,此命令创建一个空白文件
gci -r | % { Write-Host $_.Name,$_.FullName,$_.LastWriteTime } |ft -wrap | out-file output.txt
我想要 FileName
和 File Full Path
和 Last Write Time
在 输出文件这样
170801072740IMG-20170622-WA0012 (1).jpg O:0801072740IMG-20170622-WA0012 (1).jpg 1/14/2021 4:3
170801072756IMG-20170622-WA0014.jpg O:0801072756IMG-20170622-WA0014.jpg 1/14/2021 4:35:22 PM
170801072818IMG-20170624-WA0028.jpg O:0801072818IMG-20170624-WA0028.jpg 1/14/2021 4:35:22 PM
排除属性名称:
Mode LastWriteTime Length Name
---- ------------- ------ ----
还检查了另一个命令 Write-Output
gci -r | % { Write-Output $_.Name,$_.FullName,$_.LastWriteTime } >> output2.txt
此命令正在重定向输出,但输出格式不正确
输出文件:
Tuesday, March 9, 2021 1:14:42 AM
151104051548IMG_20151103_112015.jpg
O:1104051548IMG_20151103_112015.jpg
Friday, March 12, 2021 8:40:15 PM
151104051558IMG_20151103_123234.jpg
O:1104051558IMG_20151103_123234.jpg
Thursday, January 14, 2021 4:35:16 PM
151104051610IMG_20151103_123249.jpg
O:1104051610IMG_20151103_123249.jpg
Thursday, January 14, 2021 4:35:16 PM
我也尝试过 Start-Transcript
方法,但输出格式不正确
开始-转录输出文件
有什么办法可以解决这个问题吗?
gci -r -file | % { "$($_.Name) $($_.FullName) $($_.LastWriteTime)" >> G:\Test\Output.txt }
我添加了 -file 参数,因为不需要目录,因为它们包含在完整路径中。
示例输出:
Get-FileMetaDataReturnObject.ps1 G:\BEKDocs\Scripts\Functions\Get-FileMetaDataReturnObject.ps1 09/20/2018 20:03:57
Get-InstalledSoftware.ps1 G:\BEKDocs\Scripts\Functions\Get-InstalledSoftware.ps1 05/02/2020 12:24:47
Invoke-ExerciseTimer.ps1 G:\BEKDocs\Scripts\Functions\Invoke-ExerciseTimer.ps1 01/19/2017 15:01:49
New-Shortcut.txt G:\BEKDocs\Scripts\Functions\New-Shortcut.txt 01/15/2017 11:50:33
Test-RoboForm-Function.ps1 G:\BEKDocs\Scripts\Functions\Test-RoboForm-Function.ps1 02/24/2021 20:32:25
Get-DisabledServicesV1-00.ps1 G:\BEKDocs\Scripts\Get-DisabledServices\Get-DisabledServicesV1-00.ps1 01/13/2018 16:39:09
Get-DisabledServicesV2-00.ps1 G:\BEKDocs\Scripts\Get-DisabledServices\Get-DisabledServicesV2-00.ps1 01/14/2018 12:31:56
Get-WinVer-V-2-0.ps1 G:\BEKDocs\Scripts\Get-WinVer\Get-WinVer-V-2-0.ps1 03/12/2019 21:14:37
Get-WinVer-V-3-0.ps1 G:\BEKDocs\Scripts\Get-WinVer\Get-WinVer-V-3-0.ps1 12/10/2019 20:03:38
Get-WinVer-V-3-1.ps1 G:\BEKDocs\Scripts\Get-WinVer\Get-WinVer-V-3-1.ps1 12/11/2019 09:17:17
Get-WinVer-V-3-2.ps1 G:\BEKDocs\Scripts\Get-WinVer\Get-WinVer-V-3-2.ps1 01/15/2020 20:53:11