[ powershell ] 使用 windows task scheduler 跑 powershell


Powershell.exe -ExecutionPolicy Unrestricted -File D:\tar_tibco_logs.ps1
同場加映
搬移壓縮
################
# zip log into P disk
# auther: wei_liu
# team: tibco
# date: 20190401
#################

$src = "D:\path_to\*"
$dist = "P:\path_to_backup\"
$zipPath = "C:\Program Files (x86)\7-Zip\7z.exe"





#### main
# copy files to temp folder
$previous_month = (Get-Date).AddMonths(-1).ToString("yyyy_MM")
$dist_subfolder = $dist + $previous_month
New-Item -ItemType Directory -Force -Path $dist_subfolder
$files = Get-ChildItem -Path $src -Include *.log -File | Where-Object {$_.LastWriteTime -gt (Get-Date).AddMonths(-1)} | Move-Item -Destination $dist_subfolder -Force
# sz files
$target = $dist + $previous_month + ".zip"
if (-not (test-path $zipPath)) {throw $zipPath} 
set-alias sz "$zipPath"
sz a -mx=9 -tzip $target $dist_subfolder

留言