Powershell zipfile(几天前)并删除

Powershell zipfile(几天前)并删除

方法一:压缩生成文件名按照年_月_日
$Sourcepath = “C:\Users\HuiBinXiao\Desktop\test”
$Destinationpath = “C:\Users\HuiBinXiao\Desktop\zip”
$mvzip = “C:\Users\HuiBinXiao\Desktop\test*_Backup.zip”
# Optional filter to only touch files with specified extension
$mask = “*.txt”
$ZipFileName= “_Backup.zip”
#Filter to only touch files older than specified
$days = 2
$problem = $false
$date = (Get-Date).tostring(“yyyyMMddHHmm”)
$errorMessage=“no issue”

try {
# Get all items from specified path, recursing into directories but not returning directories themselves. Excluding files with modificiation dates less than $days
$files = Get-ChildItem $Sourcepath -Recurse -Include KaTeX parse error: Expected '}', got 'EOF' at end of input: mask | where {(.LastWriteTime -lt (Get-Date).AddDays(- d a y s ) ) − a n d ( days)) -and ( days))and(.psIsContainer -eq KaTeX parse error: Expected 'EOF', got '}' at position 7: false)}̲ foreach (file in $files) {
$Directory = $Sourcepath + $file.LastWriteTime.Date.ToString(‘yyyy_MM_ddHHmm’)
if (!(Test-Path $Directory)) {
New-Item $directory -type directory
}
Move-Item $file.fullname $Directory
}
$folders = Get-ChildItem $Sourcepath -Directory | % { KaTeX parse error: Expected 'EOF', got '}' at position 12: _.FullName }̲ foreach (folder in $folders) {
$zipname = $folder + $ZipFileName
if (!(test-path $zipname)){
compress-archive -LiteralPath $folder -DestinationPath $zipname
}
if (test-path $zipname){
remove-item -Recurse $folder
}
else {
Write-host $zipname + “Hello” + $folder
}
}
Move-Item -Path $mvzip -Destination $Destinationpath
}
catch {
$problem = $true
$errormessage = $_.Exception.Message
}

方法二:压缩生成文件名按照年_月_日_时_分_秒
$Sourcepath = “C:\Users\HuiBinXiao\Desktop\test”
$Destinationpath = “C:\Users\HuiBinXiao\Desktop\zip”
$mvzip = “C:\Users\HuiBinXiao\Desktop\test*_Backup.zip”
# Optional filter to only touch files with specified extension
$mask = “*.txt”
$ZipFileName= “_Backup.zip”
#Filter to only touch files older than specified
$days = 2
$problem = $false
$date = (Get-Date).tostring(“yyyyMMddHHmmss”)
$errorMessage=“no issue”

try {
# Get all items from specified path, recursing into directories but not returning directories themselves. Excluding files with modificiation dates less than $days
$files = Get-ChildItem $Sourcepath -Recurse -Include KaTeX parse error: Expected '}', got 'EOF' at end of input: mask | where {(.LastWriteTime -lt (Get-Date).AddDays(- d a y s ) ) − a n d ( days)) -and ( days))and(.psIsContainer -eq KaTeX parse error: Expected 'EOF', got '}' at position 7: false)}̲ foreach (file in $files) {
$Directory = $Sourcepath + $file.LastWriteTime.ToString(‘yyyy_MM_dd_HH_mm_ss’)
if (!(Test-Path $Directory)) {
New-Item $directory -type directory
}
Move-Item $file.fullname $Directory
}
$folders = Get-ChildItem $Sourcepath -Directory | % { KaTeX parse error: Expected 'EOF', got '}' at position 12: _.FullName }̲ foreach (folder in $folders) {
$zipname = $folder + $ZipFileName
if (!(test-path $zipname)){
compress-archive -LiteralPath $folder -DestinationPath $zipname
}
if (test-path $zipname){
remove-item -Recurse $folder
}
else {
Write-host $zipname + “Hello” + $folder
}
}
Move-Item -Path $mvzip -Destination $Destinationpath
}
catch {
$problem = $true
$errormessage = $_.Exception.Message
}

你可能感兴趣的:(Windows\Active,Directory,Powershell)