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
Powershell 使用PS复制上周';谁的日志文件?_Powershell - Fatal编程技术网

Powershell 使用PS复制上周';谁的日志文件?

Powershell 使用PS复制上周';谁的日志文件?,powershell,Powershell,我的任务是将当前的powershell脚本从收集服务器上最后一个月的IIS日志更改为每周获取日志。这周我没有看到任何语法 下面是上个月日志的当前脚本- Clear Write-Host " " Write-Host "Copying started at: " (get-date) $aDate=$(get-date).AddMonths(-1) $aDateSet=@($aDate) $firstDay = Get-Date $aDate -day 1 -hour 0 -minute 0 -

我的任务是将当前的powershell脚本从收集服务器上最后一个月的IIS日志更改为每周获取日志。这周我没有看到任何语法

下面是上个月日志的当前脚本-

Clear
Write-Host " "
Write-Host "Copying started at: " (get-date)
$aDate=$(get-date).AddMonths(-1) 
$aDateSet=@($aDate)
$firstDay = Get-Date $aDate -day 1 -hour 0 -minute 0 -second 0
$lastDay = (($firstDay).AddMonths(1).AddSeconds(-1))
Write-Host " "
get-childitem "path" | where-object {$_.lastwritetime -ge $firstDay  -and $_.lastwritetime -le $lastDay }  | copy-item -destination "path"

那么我该如何改变这一点来获取上周的日志呢?或者,使用此脚本是否可以执行此操作?

有一种方法可以选择上周的文件系统项目:

$beginningOfLastWeek = (Get-Date).Date.AddDays(-(Get-Date).DayOfWeek-1-6)
  • 获取表示上周开始的
    [DateTime]

    $beginningOfLastWeek = (Get-Date).Date.AddDays(-(Get-Date).DayOfWeek-1-6)
    
  • 获取表示本周开始的
    [DateTime]

    $beginningOfThisWeek = (Get-Date).Date.AddDays(-(Get-Date).DayOfWeek)
    
  • 在这两个时间内获取文件:

    Get-ChildItem | Where-Object { ($_.LastWriteTime -ge $beginningOfLastWeek) -and ($_.LastWriteTime -lt $beginningOfThisWeek) } ...
    

  • 这里有一种方法可以选择上周的文件系统项目:

    $beginningOfLastWeek = (Get-Date).Date.AddDays(-(Get-Date).DayOfWeek-1-6)
    
  • 获取表示上周开始的
    [DateTime]

    $beginningOfLastWeek = (Get-Date).Date.AddDays(-(Get-Date).DayOfWeek-1-6)
    
  • 获取表示本周开始的
    [DateTime]

    $beginningOfThisWeek = (Get-Date).Date.AddDays(-(Get-Date).DayOfWeek)
    
  • 在这两个时间内获取文件:

    Get-ChildItem | Where-Object { ($_.LastWriteTime -ge $beginningOfLastWeek) -and ($_.LastWriteTime -lt $beginningOfThisWeek) } ...
    

  • 我看不到任何一周的语法。
    一周是7天。希望有帮助。
    我看不出一周有什么语法。
    一周是7天。希望有帮助。