【发布时间】:2015-11-03 17:44:10
【问题描述】:
我有以下 powershell 代码,其中, folder1 中(原始)文件的备份在 folder2 中进行,并且 folder1 中的文件使用 folder3 文件进行更新。
修补程序的概念!!
cls [xml] $XML = Get-content -Path <path of xml> $main = $XML.File[0].Path.key $hotfix = $XML.File[1].Path.key $backup = $XML.File[2].Path.key Get-ChildItem -Path $main | Where-Object { Test-Path (Join-Path $hotfix $_.Name) } | ForEach-Object { Copy-Item $_.FullName -Destination $backup -Recurse -Container } write-host "`nBack up done !" Get-ChildItem -Path $hotfix | ForEach-Object {Copy-Item $_.FullName -Destination $main -force} write-host "`nFiles replaced !"
现在,由于文件的备份是在文件夹 2 中进行的,我需要创建一个日志文件,其中包含 - 进行备份的文件的名称、日期和时间、进行备份的位置
谁能帮我解决这个问题? 我做了以下代码,但它没有用,因为我无法同步两者。
cls $path = "C:\Log\Nlog.log" $numberLines = 25 For ($i=0;$i -le $numberLines;$i++) { $SampleString = "Added sample {0} at {1}" -f $i,(Get-Date).ToString("h:m:s") add-content -Path $path -Value $SampleString -Force }
感谢任何帮助或不同的方法!
【问题讨论】:
标签: powershell logging powershell-2.0