Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Logging Powershell:通过写入日志将记录文件移动到日志文件_Logging_Powershell_Archive - Fatal编程技术网

Logging Powershell:通过写入日志将记录文件移动到日志文件

Logging Powershell:通过写入日志将记录文件移动到日志文件,logging,powershell,archive,Logging,Powershell,Archive,警告:我的无知-道歉 我想使用函数“write log”写入日志文件 e、 g (偷自) 我通过一个归档脚本,通过我通过。包括 我想通过写日志在我的日志文件中记录哪些文件已经存档 目前的档案详情如下: Get-ChildItem -Path $SourceDir | Where-Object {$_.LastWriteTime.Date -lt (get-date).AddDays(-$Age) -and -not $_.PSIsContainer} | Move-Item -Destinati

警告:我的无知-道歉

我想使用函数“write log”写入日志文件 e、 g

(偷自)

我通过一个归档脚本,通过我通过。包括

我想通过写日志在我的日志文件中记录哪些文件已经存档

目前的档案详情如下:

Get-ChildItem -Path $SourceDir |
Where-Object {$_.LastWriteTime.Date -lt (get-date).AddDays(-$Age) -and -not $_.PSIsContainer} |
Move-Item -Destination $MoveDir
如何插入我的写入日志以记录我已存档的文件


谢谢

对于从Get-ChildItem返回的每个fileinfo对象,您可以在ForEach对象cmdlet中调用Move Item并写入日志。 例如:


thnx,对我有用。FYI/FWIW 1)$fileInfo.fullname 2)我肯定我看到了类似的答案,随后的帖子在管道末端反对foreach-meh-ne'er注意,它有效,我正在转移的文件数量不认为我在寻求提高性能的领域…'阿金焦油。
Get-ChildItem -Path $SourceDir |
Where-Object {$_.LastWriteTime.Date -lt (get-date).AddDays(-$Age) -and -not $_.PSIsContainer} |
Move-Item -Destination $MoveDir
Get-ChildItem -Path $SourceDir | `
Where-Object {$_.LastWriteTime.Date -lt (get-date).AddDays(-$Age) -and -not $_.PSIsContainer} | `
ForEach-Object {
$fileInfo = $_
Move-Item -Path $fileInfo -Destination $MoveDir -WhatIf
# Log your message
Write-Log -Message "moved file $fileInfo" -Path C:\MyLog.log
}