【发布时间】:2014-09-27 00:36:01
【问题描述】:
我编写了一个删除旧视频目录的脚本,它会创建一个 .txt 文件中已删除内容的日志。
在我的 Windows 7 PC 上运行脚本,记事本中的 .txt 文件将每个输出放在一个新行上。
在我的 Windows 2012 服务器上运行脚本,记事本中的 .txt 文件将输出放在同一行。如果我用写字板打开日志文件,则输出将在新行上。
powershell 脚本如下所示:
$limit = (Get-Date).AddDays(0)
$logFile = "C:\BodyCam\bodycamlog.txt"
$output = "The following directories contain incorrect video dates" + "`n"
#Throw a timestamp on the log file
Add-Content -Path $logFile "=======$(Get-Date)======="
#Get all of the paths for each camera
$paths = Get-ChildItem -Path "D:\Videos\" |Select-Object -ExpandProperty FullName
#for each path we found
foreach ($pa in $paths) {
# Delete directories older than the $limit.
$dir = Get-ChildItem -Path $pa -Recurse -Force | Where-Object { $_.PSIsContainer -and $_.CreationTime -lt $limit }
$dir | Remove-Item -Recurse -Force
$dir | Select -Expand FullName | Out-File $logFile -append
if ($dir -match "1970"){
$output += $pa + "`n"
}
}
Send-MailMessage -to "Ray <***>" -from "BodyCamScript <***>" -subject "Bad Bodycam Date Found" -body $output -SmtpServer ***
这里有什么问题?
【问题讨论】:
标签: powershell