Манипуляции с папками на PowerShell
Backup Директория в архив zip
1 2 3 4 5 6 |
$source = "C:\Folder_For_Backup" $destination = "C:\directory_with_bckp\folder_bckp_$(get-date -f yyyy_MM_dd).zip" If(Test-path $destination) {Remove-item $destination} Add-Type -assembly "system.io.compression.filesystem" [io.compression.zipfile]::CreateFromDirectory($Source, $destination) |
Отправка письма с вложенным отчетом Excel через SMTP почтовый сервер через PowerShell (.ps1)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
$CredUser = "login@yandex.ru" $CredPassword = "password" $message = new-object System.Net.Mail.MailMessage $message.From = "login@yandex.ru" $message.To.Add("email-to@gmail.com") $message.IsBodyHtml = $True $message.Subject = "Test mail Subject" $attach = new-object Net.Mail.Attachment('C:\files\report.xlsx') $message.Attachments.Add($attach) $message.body = $Body $SMTPServer = "smtp.yandex.ru" $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587) $SMTPClient.EnableSsl = $true $SMTPClient.Credentials = New-Object System.Net.NetworkCredential($CredUser, $CredPassword); $SMTPClient.Send($message) |