Here’s an excerpt from the PS Script I use to generate Outlook Signatures:
# Get Active Directory information for current user $UserName = $env:username Write-Log -LogString "Scraping Active Directory information for user: $UserName" -LogLevel 0 $Filter = "(&(objectCategory=User)(samAccountName=$UserName))" $Searcher = New-Object System.DirectoryServices.DirectorySearcher $Searcher.Filter = $Filter $ADUserPath = $Searcher.FindOne() $ADUser = $ADUserPath.GetDirectoryEntry() $ADCompany = $ADUser.company $ADCountry = $ADUser.co $ADDisplayName = $ADUser.displayName $ADFax = $AdUser.facsimileTelephoneNumber $ADSuburb = $ADUser.l $ADEmailAddress = $ADUser.mail $ADMobile = $ADUser.mobile $ADPostCode = $ADUser.postalCode $ADState = $ADUser.st $ADStreetAddress = $ADUser.streetAddress $ADTitle = $ADUser.title $ADTelePhoneNumber = $ADUser.telephoneNumber $ADWebsite = $ADUser.wWWHomePage Couple of things you might want to consider when writing your script: - Save queried values and script/template/signature timestamps to registry to avoid running unnecessarily on each logon unless something changes - Didn’t find out if this was different versions of Word Object (Microsoft.Office.Interop.Word) or PowerShell between Windows 7 and Windows 8+ machines but saving and exporting to HTML/RTF/TXT might have different syntax depending on how you do it - I noticed as well that the code I was using to set signatures as default stopped working at some point after our migration to Office 365 (Click to Run installs), didn’t really investigate though as it wasn’t a huge problem Let me know if you run into issues/need pointers. I might be able to share my script after sanitizing it. It takes in a .docx file with bookmarks as a template and generates the required files for HTML/RTF/TXT signatures only when changes are detected in either source script, source template, queried attributes or target output files (user modification). Regards, Freddy From: [email protected] [mailto:[email protected]] On Behalf Of Brian Desmond Sent: Tuesday, 28 June 2016 7:08 AM To: [email protected] Subject: RE: [NTSysADM] RE: PowerShell weaknesses One of my customers uses a product from a company called Symprex that does exactly this. It’s very inexpensive and you wouldn’t have to invent anything. Thanks, Brian Desmond w – 312.625.1438 | c – 312.731.3132 From: [email protected]<mailto:[email protected]> [mailto:[email protected]] On Behalf Of James Rankin Sent: Monday, June 27, 2016 10:58 AM To: [email protected]<mailto:[email protected]> Subject: RE: [NTSysADM] RE: PowerShell weaknesses Actually might be worth extending this debate slightly… I’m trying to build Outlook signature files on the fly using AD attributes. So I basically need to grab certain AD attributes and set them as variables. This is not a problem. However, as I am doing this at user first logon, I need to query the AD attributes in the context of the user. Get-ADUser is the cmdlet I’m using, but this is unavailable on my Windows 10 clients unless I install the RSAT. So… Is there a way to programmatically install the RSAT feature on Windows 10 with the AD PowerShell stuff enabled? I’d rather not have to go back and create a new image. I found Enable-WindowsOptionalFeature but don’t seem to be able to crack the right syntax for it… Cheers, JR From: [email protected]<mailto:[email protected]> [mailto:[email protected]] On Behalf Of Charles F Sullivan Sent: 27 June 2016 16:29 To: [email protected]<mailto:[email protected]> Subject: RE: [NTSysADM] RE: PowerShell weaknesses I was going to suggest: Get-ADUser -identity jrankin -Properties mail That will get you the defaults plus Mail. I mention this because I find it easier to remember, though of course it’s a matter of preference. From: [email protected]<mailto:[email protected]> [mailto:[email protected]<mailto:[email protected]>] On Behalf Of James Rankin Sent: Monday, June 27, 2016 10:41 AM To: [email protected]<mailto:[email protected]> Subject: [NTSysADM] RE: PowerShell weaknesses Doh! Put it in brackets would be the thing I’m missing (Get-ADUser -filter jrankin -Properties mail).mail Never mind…. ☺ From: James Rankin Sent: 27 June 2016 15:39 To: '[email protected]<mailto:[email protected]>' <[email protected]<mailto:[email protected]>> Subject: PowerShell weaknesses How can I used Get-ADUser to query a single attribute for a specific user? If I use something like Get-ADUser -filter jrankin -Properties mail To query the email address in AD, I don’t just get that attribute returned, I get a bunch of default stuff too… DistinguishedName : CN=James Rankin,OU=Desktop1,OU=Standard Users,OU=User Accounts,DC=JRR,DC=test,DC=local Enabled : True GivenName : James mail : [email protected]<mailto:[email protected]> Name : James Rankin ObjectClass : user ObjectGUID : 694d15e1-d550-483a-8f21-cb7415f05342 SamAccountName : jrankin SID : S-1-5-21-2950944927-1203068717-1704750700-1114 Surname : Rankin UserPrincipalName : [email protected]<mailto:[email protected]> Am I missing something blatantly obvious here? Cheers, James Rankin EUC Solutions Architect | 07809 668579 | [email protected]<mailto:[email protected]> One Trinity Green, Eldon Street, South Shields, Tyne & Wear, NE33 1SA Tel: 0191 481 3446 NOTICE: This email is confidential. If you are not the nominated recipient, please immediately delete this email, destroy all copies and inform the sender. Australian Maritime Systems Ltd. (AMS) prohibits the unauthorised copying or distribution of this email. This email does not necessarily express the views of AMS. AMS does not warrant nor guarantee that this email communication is free from errors, virus, interception or interference.

