Logging Powershell:通过写入日志将记录文件移动到日志文件
警告:我的无知-道歉 我想使用函数“write log”写入日志文件 e、 g (偷自) 我通过一个归档脚本,通过我通过。包括 我想通过写日志在我的日志文件中记录哪些文件已经存档 目前的档案详情如下: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
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
}