PowerShell/Exchange
Exchange et l'automatisation.
Création d'une signature pour tous les comptes
Création d'une signature au format HTML pour tous les comptes récupérés de l'AD.
Etape 1
#import the active directory module which is needed for Get-ADUser
import-module activedirectory
#set folder location for files, the folder must already exist
$save_location = 'c:\file_location\'
#$users = Get-ADUser -filter * -searchbase "OU=Testing,OU=Staff,OU=Test Users,DC=bigcheese,DC=com" -Properties * -Credential bigcheese\admin -Server bigcheese.com
$users = Get-ADUser -filter * -searchbase "OU=Testing,OU=Staff,OU=Test Users,DC=bigcheese,DC=com" -Properties *
foreach ($user in $users) {
$full_name = “$($user.GivenName) $($User.Surname)”
$account_name = "$($User.sAMAccountName)"
$job_title = "$($User.title)"
$location = "$($User.office)"
$dept = "$($User.department)"
$comp = "$($User.company)"
$email = "$($User.emailaddress)"
$phone = "$($User.telephoneNumber)"
$logo = "$($User.wWWHomePage)"
#We need to construct and write the html signature file
$output_file = $save_location + $account_name + ".htm"
Write-Host "Now attempting to create signature html file for " $full_name
"<span style=`"font-family: calibri,sans-serif;`"><strong>" + $full_name + "</strong><br />", $job_title + " - " + $location + "<br />", $dept + "<br />", $comp + "<br />", $phone + "<br />", "</span><br />", "<img alt=`"corporate logo`" border=`"0`" height=`"90`" src=`"" + $logo + "`" width=`"385`" />" | Out-File $output_file
}
Etape 2
#set folder location for files, the folder must allready exist
$save_location = 'file_location'
$email_domain = '@bigcheese.com'
#connect to O365 tenant
$Cred = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $Cred -Authentication Basic –AllowRedirection
Import-PSSession $Session
#Get a list of all the filenames in the target folder
$sig_files = Get-ChildItem -Path $save_location
#Now push the html to the users signature
foreach ($item in $sig_files) {
$user_name = $($item.Basename) + $email_domain
$filename = $save_location + $($item.Basename) + ".htm"
Write-Host "Now attempting to set signature for " $user_name
set-mailboxmessageconfiguration -identity $user_name -signaturehtml (get-content $filename) -autoaddsignature $true
}
#disconnect O365 connection
get-PSSession | remove-PSSession
Etape 3
set-mailboxmessageconfiguration -identity $user_name -signaturehtml (get-content $filename) -autoaddsignature $true
Liste de certaines propriétés d'un compte Exchange
Liste de certaintes propriétés d'un compte Exchange :
get-MailboxMessageConfiguration -Identity dupondj
Le résultat est :
RunspaceId : 16e07c9c-a804-12ba-83d1-93f297gb4413 AfterMoveOrDeleteBehavior : OpenNextItem NewItemNotification : All EmptyDeletedItemsOnLogoff : False AutoAddSignature : False AutoAddSignatureOnReply : False SignatureText : SignatureHtml : AutoAddSignatureOnMobile : True SignatureTextOnMobile : UseDefaultSignatureOnMobile : True DefaultFontName : Calibri DefaultFontSize : 3 DefaultFontColor : #000000 DefaultFontFlags : Normal AlwaysShowBcc : False AlwaysShowFrom : False DefaultFormat : Html ReadReceiptResponse : DoNotAutomaticallySend PreviewMarkAsReadBehavior : OnSelectionChange PreviewMarkAsReadDelaytime : 5 ConversationSortOrder : ChronologicalNewestOnTop ShowConversationAsTree : False HideDeletedItems : False SendAddressDefault : EmailComposeMode : Inline CheckForForgottenAttachments : True AreFlaggedItemsPinned : False IsReplyAllTheDefaultResponse : True KeyboardShortcutsMode : Owa LinkPreviewEnabled : True ShowPreviewTextInListView : True ShowUpNext : True GlobalReadingPanePosition : Right IsFavoritesFolderTreeCollapsed : False IsMailRootFolderTreeCollapsed : False MailFolderPaneExpanded : True IsHashtagTreeCollapsed : False IsGroupsTreeCollapsed : False GroupSuggestionDismissalCount : 0 GroupSuggestionDismissalDate : ShowSenderOnTopInListView : True ShowReadingPaneOnFirstLoad : False NavigationPaneViewOption : Default AllOwaConfiguration : PreferAccessibleContent : False MailboxOwnerId : php.local/CAP/Dupond Jean Identity : php.local/CAP/Dupond Jean IsValid : True ObjectState : Unchanged
Quelques commandes utiles
Liste propriétés d'une boite de messagerie :
Get-Mailbox -Identity "dupondj" | fl
Liste des boites qui ne sont pas affichées dans l'annuaire, avec tri sur la colonne "Alias" :
Get-Mailbox -ResultSize Unlimited -Filter {HiddenFromAddressListsEnabled -eq $True} | Sort-Object alias
Masquer une boite dans l'annuaire général d'Exchange :
Set-Mailbox -Identity "dupondj" -HiddenFromAddressListsEnabled $True