Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| kb_it:powershell_dev [2025/02/03 11:12] – befe | kb_it:powershell_dev [2025/02/20 09:23] (Version actuelle) – befe | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | ====== PowerShell ====== | ||
| + | |||
| + | ===== Envoyer un email ===== | ||
| + | |||
| + | <code pwsh> | ||
| + | $SMTP_HOST = " | ||
| + | $SMTP_PORT = 25 | ||
| + | $SMTP_SSL = $False | ||
| + | $SMTP_USER = " | ||
| + | $SMTP_PWD = " | ||
| + | $MAIL_ATTACHMENT = "" | ||
| + | |||
| + | # Paramètres système | ||
| + | $ErrorActionPreference = " | ||
| + | [Console]:: | ||
| + | |||
| + | Function Main { | ||
| + | param( | ||
| + | [string] $From = " | ||
| + | [string] $To = " | ||
| + | [string] $Subject = "SMTP Client Submission - $(Get-Date -Format g)", | ||
| + | [string] $Body = "This is a test email using SMTP Client Submission" | ||
| + | ) | ||
| + | Send-Mail -From $From -To $To -Subject $Subject -Body $Body | ||
| + | } | ||
| + | |||
| + | Function Send-Mail { | ||
| + | param( | ||
| + | [string] $From = " | ||
| + | [string] $To = " | ||
| + | [string] $Subject = "SMTP Client Submission - $(Get-Date -Format g)", | ||
| + | [string] $Body = "This is a test email using SMTP Client Submission" | ||
| + | ) | ||
| + | |||
| + | $mailParams = @{ | ||
| + | SmtpServer | ||
| + | Port = $SMTP_PORT | ||
| + | From = $From | ||
| + | To = $To | ||
| + | Subject | ||
| + | Body = $Body | ||
| + | UseSSL | ||
| + | DeliveryNotificationOption = " | ||
| + | } | ||
| + | | ||
| + | if ((Get-Variable SMTP_USER -Scope Script -ErrorAction " | ||
| + | $mailParams.Credential = New-Object System.Management.Automation.PSCredential($SMTP_USER, | ||
| + | } | ||
| + | if ($MAIL_ATTACHMENT -ne "" | ||
| + | $mailParams.Attachment = $MAIL_ATTACHMENT | ||
| + | } | ||
| + | |||
| + | Send-MailMessage @mailParams | ||
| + | } | ||
| + | |||
| + | # Traitement | ||
| + | Main @args | ||
| + | </ | ||
| + | |||
| + | <code pwsh> | ||
| + | mail.ps1 -From " | ||
| + | </ | ||
| + | |||
| + | ===== Active Directory ===== | ||
| + | |||
| + | ==== Supprimer un object protégé contre la suppression accidentelle ==== | ||
| + | |||
| + | <code pwsh> | ||
| + | Get-ADObject -Server localhost: | ||
| + | Set-ADObject -ProtectedFromAccidentalDeletion: | ||
| + | Remove-ADOrganizationalUnit -Confirm: | ||
| + | </ | ||