{"id":1515,"date":"2024-03-29T17:34:53","date_gmt":"2024-03-29T16:34:53","guid":{"rendered":"https:\/\/www.delixirpro.com\/blog\/?p=1515"},"modified":"2024-03-29T17:49:57","modified_gmt":"2024-03-29T16:49:57","slug":"script-powershell-de-notification-par-courrier-electronique-des-replications-hyper-v","status":"publish","type":"post","link":"https:\/\/www.delixirpro.com\/blog\/2024\/03\/29\/script-powershell-de-notification-par-courrier-electronique-des-replications-hyper-v\/","title":{"rendered":"Script PowerShell de notification par courrier \u00e9lectronique des r\u00e9plications Hyper-V."},"content":{"rendered":"\n<p>Voici un exemple de script d&rsquo;envoie de notification par courrier \u00e9lectronique de r\u00e9plication Hyper-V ainsi qu&rsquo;un autre qui permet de crypter un mot de passe et de le stocker dans un fichier texte.<\/p>\n\n\n\n<p>Commen\u00e7ons par crypter le mot de passe puis le stocker.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Read-Host -Prompt \u201cEnter your password\u201d -AsSecureString | ConvertFrom-SecureString | Out-File \u00ab\u00a0C:\\batch\\cred.txt\u00a0\u00bb<\/p>\n<\/blockquote>\n\n\n\n<p>Maintenant voici le script d&rsquo;envoie de notification par mail. Il peut ensuite \u00eatre ex\u00e9cut\u00e9 en tant que t\u00e2che planifi\u00e9e sur l&rsquo;h\u00f4te Hyper-V pour envoyer des notifications par courrier \u00e9lectronique. Le compte ex\u00e9cutant le script doit disposer des autorisations Hyper-V.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>#  Get date in UK format day\/month\/year<br>$date = Get-Date -Format dd\/MM\/yy<\/p>\n\n\n\n<p># Variables<br>$MailFrom = &lsquo;hyperv_replica@yourdomain.com&rsquo;<br>$MailTo = &lsquo;you@yourdomain.com&rsquo;<br>$MailSubject = \u00ab\u00a0Hyper-V Replica Report $date\u00a0\u00bb<br>$MailServer = &lsquo;smtp.yourdomain.coml&rsquo;<br>$User = \u00ab\u00a0hyperv_replica@yourdomain.com\u00a0\u00bb<br>$PWord = Get-Content \u00ab\u00a0C:\\batch\\For_Notification_Hyper-V_Replication\\cred.txt\u00a0\u00bb | ConvertTo-SecureString -Force<br>$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord<\/p>\n\n\n\n<p># Get replication status in HTML format<br>$status = Get-VMReplication | Select-Object Name, lastreplicationtime, Health | ConvertTo-Html<\/p>\n\n\n\n<p># Send email message<br>Send-MailMessage -From $MailFrom -To $MailTo -Subject $MailSubject -BodyAsHtml -Body \u00ab\u00a0$status\u00a0\u00bb -SmtpServer $MailServer -usessl -Port 587 -Credential $Credential<\/p>\n<\/blockquote>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"403\" src=\"https:\/\/www.delixirpro.com\/blog\/wp-content\/uploads\/2024\/03\/Powershell2-1024x403.jpg\" alt=\"\" class=\"wp-image-1521\" srcset=\"https:\/\/www.delixirpro.com\/blog\/wp-content\/uploads\/2024\/03\/Powershell2-1024x403.jpg 1024w, https:\/\/www.delixirpro.com\/blog\/wp-content\/uploads\/2024\/03\/Powershell2-300x118.jpg 300w, https:\/\/www.delixirpro.com\/blog\/wp-content\/uploads\/2024\/03\/Powershell2-768x302.jpg 768w, https:\/\/www.delixirpro.com\/blog\/wp-content\/uploads\/2024\/03\/Powershell2.jpg 1265w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Source :<br><a href=\"https:\/\/chrishayward.co.uk\/2015\/11\/17\/hyper-v-2012-r2-hyper-v-replica-email-script\/\n\">https:\/\/chrishayward.co.uk\/2015\/11\/17\/hyper-v-2012-r2-hyper-v-replica-email-script\/<br><\/a><a href=\"https:\/\/learn.microsoft.com\/en-us\/answers\/questions\/137419\/powershell-script-get-hyper-v-and-send-emailmessag\">https:\/\/learn.microsoft.com\/en-us\/answers\/questions\/137419\/powershell-script-get-hyper-v-and-send-emailmessag<\/a><br><a href=\"https:\/\/blog.johanpersson.nu\/2013\/03\/07\/check-hyper-v-replication-status-using-powershell\/\">https:\/\/blog.johanpersson.nu\/2013\/03\/07\/check-hyper-v-replication-status-using-powershell\/<\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Voici un exemple de script d&rsquo;envoie de notification par courrier \u00e9lectronique de r\u00e9plication Hyper-V ainsi qu&rsquo;un autre qui permet de crypter un mot de passe et de le stocker dans un fichier texte. Commen\u00e7ons&#46;&#46;&#46;<\/p>\n","protected":false},"author":6,"featured_media":1521,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[77,83],"class_list":["post-1515","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tech-tips","tag-hyper-v","tag-powershell"],"_links":{"self":[{"href":"https:\/\/www.delixirpro.com\/blog\/wp-json\/wp\/v2\/posts\/1515","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.delixirpro.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.delixirpro.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.delixirpro.com\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.delixirpro.com\/blog\/wp-json\/wp\/v2\/comments?post=1515"}],"version-history":[{"count":3,"href":"https:\/\/www.delixirpro.com\/blog\/wp-json\/wp\/v2\/posts\/1515\/revisions"}],"predecessor-version":[{"id":1523,"href":"https:\/\/www.delixirpro.com\/blog\/wp-json\/wp\/v2\/posts\/1515\/revisions\/1523"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.delixirpro.com\/blog\/wp-json\/wp\/v2\/media\/1521"}],"wp:attachment":[{"href":"https:\/\/www.delixirpro.com\/blog\/wp-json\/wp\/v2\/media?parent=1515"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.delixirpro.com\/blog\/wp-json\/wp\/v2\/categories?post=1515"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.delixirpro.com\/blog\/wp-json\/wp\/v2\/tags?post=1515"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}