Poweshell

Копирование файлов txt по дню недели из $dir в $target

Get-ChildItem -Path $dir -filter *.txt | Where-Object { $_.lastwritetime.DayOfWeek -eq 0}| Copy-Item -Destination $target

Копирование файлов txt по дню месяца из $dir в $target

Get-ChildItem -Path $dir -filter *.txt | Where-Object { $_.lastwritetime.Day -eq 1 -OR $_.lastwritetime.Day -eq 17}| Copy-Item -Destination $target

Удаление всех файлов txt из $dir кроме 7 последних

$files = Get-ChildItem $dir | where {$_.name -like "*.txt" }| Sort-Object CreationTime
$files | select -First ($files.Count -7) | Remove-Item -Force

Копирование $file с ftp $server директории $dir в локальную папку $target

$WC = new-object System.Net.WebClient
$WC.Proxy = $null
$Wc.Credentials = New-Object System.Net.NetworkCredential($user,$pwd)
try{
$url = "ftp://${server}/${dir}/${file}"
$WC.DownloadFile($url,"${target}\${file}")
}catch{
Write-Output $_
}
  • 18.07.2023