USA Finance

Aug 13 2017

Powershell: Script to set Outlook 2010 #how #to #write #a #powershell #script


#

Powershell: Script to set Outlook 2010/2013 signature using information populated from Active Directory

Write-Output “Setting signature for Office 2013 as forced”

If ( Get-ItemProperty -Name ‘NewSignature’ -Path HKCU. ‘\Software\Microsoft\Office\15.0\Common\MailSettings’ -ErrorAction SilentlyContinue ) < >

New-ItemProperty HKCU. ‘\Software\Microsoft\Office\15.0\Common\MailSettings’ -Name ‘NewSignature’ -Value $SignatureName -PropertyType ‘String’ -Force

If ( Get-ItemProperty -Name ‘ReplySignature’ -Path HKCU. ‘\Software\Microsoft\Office\15.0\Common\MailSettings’ -ErrorAction SilentlyContinue ) < >

New-ItemProperty HKCU. ‘\Software\Microsoft\Office\15.0\Common\MailSettings’ -Name ‘ReplySignature’ -Value $SignatureName -PropertyType ‘String’ -Force

Thomas Hanley

Excellent article Daniel! For those of us still plowing through the learning curve would you mind expanding on the Step by Step section please? Particularly step #2 and #4. I have *.docx file formatted but not sure if it needs to be bookmarks or keywords or what. An example would be great. Step #4, does this get run via Logon spcript in Active Directory or GPO or somewhere else? Thank you very much in advance.

Thanks Thomas! I will put some more information in the post You can deploy it via login script or GPO, but I would recommend to create a package in SCCM and deploy it to the clients. Are you using SCCM or any other deployment solution?

What you need to do in step 2 is to add text that matches the ones in the script and it will replace them with the property found in Active Directory.

For example, if you want to use DisplayName (e.g Sam Smith) from AD, the script will look in the document for DisplayName and change it to the property stored in the variable earlier:

Here the script gets the DisplayName from AD:

Here it looks for text in the document:

#User Name $ Designation
$FindText = DisplayName

And here it replaces the text with the DisplayName property stored in AD

The script gets all the information from the logged on user.

If you have any further questions, feel free to ask them

Christoph

This is very useful, Thank you very much. But I can t get it work by GPO to run at login. I suspect the script is running in the system context by using the GPO. SCCM would be no option because I am using Xenapp. Do you have any idea to run that script on every client at every login?
Thanks in advance
Christoph

Manny

I ve tried this script but I get errors:

You cannot call a method on a null-valued expression.
At C:\Users\manny.landsman\Sig.ps1:125 char:43
+ $ReplaceText = $ADDescription.ToString ()
+ CategoryInfo. InvalidOperation: (ToString:String) [], RuntimeException
+ FullyQualifiedErrorId. InvokeMethodOnNull

It does this for every line during the AD query,

Samuel Alkobi

Hey Daniel! This script is awesome! We actually have a VBS script that does exactly this, but i ve seen it hang if/when you launch Outlook while the script is still running I haven t tested this out just yet but i was wondering if the runtime on the powershell 1 is better or if you ve seen any conflicts in outlook when running this?

Hey! The script will close Outlook if it s running, because, as you mentioned, there might be conflicts when having Outlook opened while the script is running. I haven t had any issues with this I will release a new version of this script in the next couple of days, so stay tuned.

Talha Shaikh

HI The script is great and worked well for me, I was wondering if you can help with a slight customization. I want the signature to be set as default for new messages only but i want the option to allow staff to edit and put their mobile numbers in. At the moment if i force it it greys out the options and does not allow modification. On the other hand if I don t force it it does not set as their default if they already have their own signature.

Reyale

This script is very well. I only have a question. How would it be possible to completely erase the line who contain nothing ?

In place of replace the text, completely delete the line ?

ps. sorry for my english

Chris

Just wanted to say thank you for taking the time to work this out. I tweaked it heavily to suit my signature needs, and ended up using the script to create four distinct signatures per user. Thank you, thank you, thank you.

Thanks for the kind words and I m happy that the script helped you!

Michael Nipgaard

Wow! I didn t know you responded on post (I thought I would have gotten an email about it)
But great that you are working on an update.
In the meantime I have looked some more into it and I think the problem is the Outlook 2013 version and not the powershell. I use Office 365 and have installed Outlook on my pc, which is an 365 version of Outlook 2013.
I have tried to see if I could get the version number, so I could do an compare on 2013 versions.
This has not been possible yet. But maybe it will help you or anybody else to find an solution on the [ref] issue.
I wonder why nobody else has come across this issue.
looking forward to see the update

XPSIT

do you know how I can set more then one default signature?

My Problem is I have two mail adresses in one outlook profile.
Mail adress A needs another default signature as mail adress B.

I have no idea how I can set two different default signatures.

Paul Daniel

Hi Xpsit. you will not get it to work with multiple profiles. While the powershell script can work to some extend, if you don t use images, there is no point in spending so much time trying to get it work, when there are so many cheap solutions out there. Check out outlooksignatures.com for example, a simple version that will handle multiple profiles, visual design and the price is marginal

rva-lc

The mail field is not updating in the signature, all fields are completed in AD. I ve tried other iterations of mail in the template (mail, emailAddress, email, etc etc). Any idea why that field wouldn t fill even though it is completed in AD? All other AD fields fill in.

rva-lc

After looking more closely I didn t find a mail item in the script and it wasn t included in the template. I added the mail item and pointed it to find the field in AD. Thanks. But now another question If you use the ForceSignature = 1 and then decide not to use it, how do you update the Outlook settings? I changed the ForceSignature back to 0 and changed the version number and ran the script again but the Signature options in Outlook are still locked. I looked for the registry items listed in the script to directly edit those but now they don t exist. Should I just reinstall Outlook or is there an easier way?

Leave a Reply Cancel reply

About the author


Daniel Classon works as a Senior Consultant at Lumagate, focusing on Microsoft Configuration Manager, Windows 10 and Powershell


Written by admin


Leave a Reply

Your email address will not be published. Required fields are marked *