The set-mailboxmessageconfiguration command is the one that does the magic and puts the HTML file into the user’s signature. set-mailboxmessageconfiguration -identity $user_name -signaturehtml (get-content $filename) -autoaddsignature $true This result is quite handy as, in this instance, it’s also providing us the user name for the user we are going to edit once it is combined with the $email_domain. $($item.Basename) retrieves just the file name with no extension. The cmdlet creates an array of the file names so we can run through the individual file names in a For loop. Get-ChildItem is used to create a list of all the files in the $save_location folder. You’ll be prompted for some login credentials for Office 365 these credentials must be for a user who can access and write to the users’ signatures. The $save_location variable must be set to the folder containing the HTML signature files. Set-mailboxmessageconfiguration -identity $user_name -signaturehtml (get-content $filename) -autoaddsignature $true Write-Host "Now attempting to set signature for " $user_name $filename = $save_location + $($item.Basename) + ".htm" #Now push the html to the users signature $sig_files = Get-ChildItem -Path $save_location #Get a list of all the filenames in the target folder $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $Cred -Authentication Basic –AllowRedirection #set folder location for files, the folder must allready exist
Now that we’ve created an HTML signature file for each user, we have to connect to Office 365 and push this HTML to their signature. You can open this file in a web browser to make sure it looks as you expected. Next, the script constructs a CSS/HTML file containing the selected fields and writes the file to the $save_location folder in the format username.htm. The script uses the wWWHomePage field to store the location to a publicly accessible image that will be included in our signature file.
A full list of the fields can be found here. The For loop goes through this array, pulls out the specified AD fields, and stores them as parameters. Properties of a user object in Active Directory Now that we have all the properties from all users in that OU as an array in $users, we can process the user information. The -searchbase parameter is used to target it to a specific OU. The script uses the Get-ADUser cmdlet to retrieve information from AD. Write-Host "Now attempting to create signature html file for " $full_name $output_file = $save_location + $account_name + ".htm" #We need to construct and write the html signature file $account_name = "$($User.sAMAccountName)" $full_name = “$($user.GivenName) $($User.Surname)” $users = Get-ADUser -filter * -searchbase "OU=Testing,OU=Staff,OU=Test Users,DC=bigcheese,DC=com" -Properties * #$users = Get-ADUser -filter * -searchbase "OU=Testing,OU=Staff,OU=Test Users,DC=bigcheese,DC=com" -Properties * -Credential bigcheese\admin -Server #set folder location for files, the folder must already exist #import the active directory module which is needed for Get-ADUser The save location must exist and should be completely empty when the script first runs on subsequent runs, the script will overwrite the output.
The script first imports the required PowerShell module. I welcome suggestions for additions and modifications to the scripts.
The scripts are provided merely as a starting base for you to work from.
It’s also possible that you could combine the two scripts into one and run the combined script as a scheduled job.
I tested the create script on a Windows Server 2008 R2 Domain Controller and the push script on a Windows 7 Enterprise 64-bit client, but there is no reason why, in your environment, you couldn’t run both from the server. Note that there is currently no error checking, and you must test the scripts before deploying them in a production environment. These scripts are provided for you to use at your own risk.