none
PowerShell command or line to set the Default font for MS Word ?

    Question

  • Hi All,

    I've got the below PowerShell script for setting the default Outlook email signature: https://github.com/a118n/poweradmin/blob/master/Set-Outlook-Signature/Set-Outlook-Signature.ps1

    Now I wonder what's the command to set the font to be "Courier New" rather than the default Calibri font ? 

    I have tried to use:

    # Save Signature files in multiple extensions (needed for Outlook)
    $saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatHTML");
    $path = "$LocalSignaturePath\$SignatureName.htm"
    $MSWord.ActiveDocument.Range.Font.Name = "Courier New"
    $MSWord.ActiveDocument.SaveAs([ref]$path, [ref]$saveFormat)

    $saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatRTF");
    $path = "$LocalSignaturePath\$SignatureName.rtf"
    $MSWord.ActiveDocument.SaveAs([ref] $path, [ref]$saveFormat)

    $saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatText");
    $path = "$LocalSignaturePath\$SignatureName.txt"
    $MSWord.ActiveDocument.SaveAs([ref] $path, [ref]$SaveFormat)

    $MSWord.ActiveDocument.Close()
    $MSWord.Quit()

    But it does not recognize the "Name" as the property.

    Any help would be greatly appreciated.

    Thanks,


    /* Server Support Specialist */

    Tuesday, May 8, 2018 3:59 AM

All replies

  • Try with // myRange.Font.Name = "Courier New"

    else check with this for default sign   https://community.spiceworks.com/scripts/show/4024-set-outlook-signature

    Replace font as Courier New( font-family: 'Courier New' )


    • Edited by Partha1012 Tuesday, May 8, 2018 4:16 AM
    Tuesday, May 8, 2018 4:10 AM
  • Try with // myRange.Font.Name = "Courier New"

    else check with this for default sign   https://community.spiceworks.com/scripts/show/4024-set-outlook-signature

    Replace font as Courier New( font-family: 'Courier New' )


    Hi Partha,

    Thanks for the reply, but I have already got the MS Word document template, so with the script I got above https://github.com/a118n/poweradmin/blob/master/Set-Outlook-Signature/Set-Outlook-Signature.ps1

    I just need one more line to change the default text into Courier New, the example that you posted is for creating the HTML template manually which is reinventing the wheel from scratch? 


    /* Server Support Specialist */

    Tuesday, May 8, 2018 4:25 AM
  • What is "default text".   You have to select an object to set its font. Fonts are set specific to an object or selection.

    Setting the global font only changes new text entered as text.


    \_(ツ)_/

    Tuesday, May 8, 2018 4:33 AM
    Moderator
  • What is "default text".   You have to select an object to set its font. Fonts are set specific to an object or selection.

    Setting the global font only changes new text entered as text.


    \_(ツ)_/

    Where can I find the Default text property ?

    Because there is Default Text property set in the PowerShell script to set the email signature.

    The MS word default Normal.Dot is set to Calibri.


    /* Server Support Specialist */


    Tuesday, May 8, 2018 4:41 AM
  • What is "default text".   You have to select an object to set its font. Fonts are set specific to an object or selection.

    Setting the global font only changes new text entered as text.


    \_(ツ)_/


    Where can I find the Default text property ?

    /* Server Support Specialist */

    There is no such property.


    \_(ツ)_/

    Tuesday, May 8, 2018 4:42 AM
    Moderator
  • What is "default text".   You have to select an object to set its font. Fonts are set specific to an object or selection.

    Setting the global font only changes new text entered as text.


    \_(ツ)_/


    Where can I find the Default text property ?

    /* Server Support Specialist */

    There is no such property.


    \_(ツ)_/

    Hm.. I have tried all below but nothing is working:

    $MSWord.ActiveDocument.Range.Font.Name = 'Courier New'

    $MSWord.ActiveDocument.FontName = 'Courier New'

    $MSWord.ActiveDocument.Text.Selection.Font= 'Courier New'

    $MSWord.ActiveDocument.Text.Selection.Font.Name = 'Courier New'


    /* Server Support Specialist */

    Tuesday, May 8, 2018 4:47 AM
  • Try learning Word programming an the Word object model.  It will help you understand what is happening and why nothing works.

    https://msdn.microsoft.com/en-us/library/kw65a0we.aspx

    You need a selection of some kind and then change the selection font.

    $doc.SelectAllEditableRanges()

    or use the story method I posted above.


    \_(ツ)_/

    Tuesday, May 8, 2018 4:59 AM
    Moderator
  • Try learning Word programming an the Word object model.  It will help you understand what is happening and why nothing works.

    https://msdn.microsoft.com/en-us/library/kw65a0we.aspx

    You need a selection of some kind and then change the selection font.

    $doc.SelectAllEditableRanges()

    or use the story method I posted above.


    \_(ツ)_/

    OK, so in this code, where shall I insert that command or line ?

    # Signature variables
    $SignatureName = "Company Default Signature" # Change this to whatever your file name is
    $LocalSignaturePath = (Get-Item env:appdata).Value + "\Microsoft\Signatures"
    $RemoteSignature = "\\domain.com\sysvol\domain.com\scripts\$SignatureName.docx" # Point this to where your signature is located on a network share
    
    
    # Get Active Directory information for current user
    $Searcher = New-Object System.DirectoryServices.DirectorySearcher
    $Searcher.Filter = "(&(objectCategory=User)(samAccountName=$env:username))"
    $ADUserPath = $Searcher.FindOne()
    $ADUser = $ADUserPath.GetDirectoryEntry()
    
    # Get user properties for signature
    $ADDisplayName = $ADUser.DisplayName
    $ADLocalizedName = $ADUser.extensionAttribute10
    $ADEmailAddress = $ADUser.mail
    $ADTitle = $ADUser.title
    $ADLocalizedTitle = $ADUser.extensionAttribute13
    $ADTelephoneNumber = $ADUser.telephoneNumber
    $ADMobilePhone = $ADUser.mobile
    $ADDepartment = $ADUser.department
    $ADCompany = $ADUser.company
    $ADLocalizedCompany = $ADUser.extensionAttribute1
    
    
    ### Copy signature templates to local Signature folder
    
    # If there's no folder, create it
    if (-Not (Test-Path $LocalSignaturePath)) { New-Item -Path $LocalSignaturePath -Itemtype Directory -Force | Out-Null }
    
    # If there's a file with the same name, delete it and create a folder
    if (-Not (Test-Path $LocalSignaturePath -pathType container)) {
    
        Remove-Item -Path $LocalSignaturePath -Force
        New-Item -Path $LocalSignaturePath -Itemtype Directory -Force | Out-Null
    }
    
    # Copy template file to user's appdata
    Copy-Item -Path $RemoteSignature -Destination $LocalSignaturePath -Force
    
    
    ### Insert variables from Active Directory to Signature File
    
    # Parameters for changing strings in Word file
    $ReplaceAll = 2
    $FindContinue = 1
    $MatchCase = $False
    $MatchWholeWord = $True
    $MatchWildcards = $False
    $MatchSoundsLike = $False
    $MatchAllWordForms = $False
    $Forward = $True
    $Wrap = 1
    $Format = $False
    
    $MSWord = New-Object -com word.application
    
    $MSWord.Documents.Open("$LocalSignaturePath\$SignatureName.docx")
    
    $FindText = "AD_DisplayName"
    $ReplaceText = $ADDisplayName.ToString()
    $MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,	$MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap,	$Format, $ReplaceText, $ReplaceAll)
    
    $FindText = "AD_Title"
    $ReplaceText = $ADTitle.ToString()
    $MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,	$MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap,	$Format, $ReplaceText, $ReplaceAll)
    
    $FindText = "AD_Department"
    $ReplaceText = $ADDepartment.ToString()
    $MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,	$MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap,	$Format, $ReplaceText, $ReplaceAll)
    
    $FindText = "AD_Telephone"
    $ReplaceText = $ADTelephoneNumber.ToString()
    $MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,	$MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap,	$Format, $ReplaceText, $ReplaceAll)
    
    $FindText = "AD_MobilePhone"
    $ReplaceText = $ADMobilePhone.ToString()
    $MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,	$MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap,	$Format, $ReplaceText, $ReplaceAll)
    
    $FindText = "AD_Company"
    $ReplaceText = $ADCompany.ToString()
    $MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,  $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap, $Format, $ReplaceText, $ReplaceAll)
    
    $MSWord.Selection.Find.Execute("AD_Email")
    $MSWord.ActiveDocument.Hyperlinks.Add($MSWord.Selection.Range, "mailto:"+$ADEmailAddress.ToString(), $missing, $missing, $ADEmailAddress.ToString())
    
    
    # Save Signature files in multiple extensions (needed for Outlook)
    $saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatHTML");
    $path = "$LocalSignaturePath\$SignatureName.htm"
    $MSWord.ActiveDocument.SaveAs([ref]$path, [ref]$saveFormat)
    
    $saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatRTF");
    $path = "$LocalSignaturePath\$SignatureName.rtf"
    $MSWord.ActiveDocument.SaveAs([ref] $path, [ref]$saveFormat)
    
    $saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatText");
    $path = "$LocalSignaturePath\$SignatureName.txt"
    $MSWord.ActiveDocument.SaveAs([ref] $path, [ref]$SaveFormat)
    
    $MSWord.ActiveDocument.Close()
    $MSWord.Quit()
    
    
    # Set signature as default
    $MSWord = New-Object -com word.application
    $EmailOptions = $MSWord.EmailOptions
    $EmailSignature = $EmailOptions.EmailSignature
    $EmailSignatureEntries = $EmailSignature.EmailSignatureEntries
    $EmailSignature.NewMessageSignature = $SignatureName
    $EmailSignature.ReplyMessageSignature = $SignatureName
    $MSWord.Quit()

    Thanks in advance.

    I just need to know the very last bit of the line.


    /* Server Support Specialist */

    Tuesday, May 8, 2018 5:03 AM
  • Insert where you need it.  It is your document. 

    If you use a template to build a signature and use the correct methods of generating the signature objects you will not need to alter the font.  JUst set the font on the template.  Define fields in the template for all items you want to insert then just use the API calls to create the signature and assign it.

    The code you copied is based on a very old VBScript routine that was never a good way to do this.  Look in the Gallery for methods that use a template and you  will have much more control.


    \_(ツ)_/

    Tuesday, May 8, 2018 5:08 AM
    Moderator
  • If you add this line to the script before entering and text it should set the font for all text entered.

    $wd.Selection.Font.Name = 'Verdana Pro Black'


    \_(ツ)_/

    Tuesday, May 8, 2018 5:10 AM
    Moderator
  • Insert where you need it.  It is your document. 

    If you use a template to build a signature and use the correct methods of generating the signature objects you will not need to alter the font.  JUst set the font on the template.  Define fields in the template for all items you want to insert then just use the API calls to create the signature and assign it.

    The code you copied is based on a very old VBScript routine that was never a good way to do this.  Look in the Gallery for methods that use a template and you  will have much more control.


    \_(ツ)_/

    Hi JRV,

    Yes, I have created the .DOCX of the email signature template like below:

    AD_DisplayName 
    --------------
    AD_Title AD_City Division
    Phone: AD_Telephone
    Mobile / Cell: AD_MobilePhone
    Website: www.domain.com
    [Company Graphic & Logo]

    so the PowerShell script basically just replacing the data pulled from the AD.

    However, even though the Signature template.DOCX has been set to Consolas, the signature end result is still resulting in Calibri ?

    Is this due to the Default Normal.Dotx in the Group Policy is set to Calibri ?


    /* Server Support Specialist */

    Tuesday, May 8, 2018 5:23 AM
  • If you add this line to the script before entering and text it should set the font for all text entered.

    $wd.Selection.Font.Name = 'Verdana Pro Black'


    \_(ツ)_/

    OK, I have added like below:

    $MSWord = New-Object -com word.application
    $MSWord.Documents.Open("$LocalSignaturePath\$SignatureName.docx")
    $MSWord.Documents.Selection.Font.Name = 'Verdana'

    But somehow the font is still not set as Verdana nor Consolas ?


    /* Server Support Specialist */

    Tuesday, May 8, 2018 5:24 AM
  • You have to use the template to create a new document.  You cannot just open the template as a document.  The template must be saved as a template.

    A template is named DOTX.  We create a document from a template like this:

    $doc = $wd.Documents.Add(<template file path>)

    This will set all fonts and styles in the new document from the template.

    As I noted the script you are starting from is bogus.  It is not how we build signatures.  It was copied from an old VBScript that was also incorrectly designed.


    \_(ツ)_/


    Tuesday, May 8, 2018 5:30 AM
    Moderator
  • You have to use the template to create a new document.  You cannot just open the template as a document.  The template must be saved as a template.

    A template is named DOTX.  We create a document from a template like this:

    $doc = $wd.Documents.Add(<template file path>)

    This will set all fonts and styles in the new document from the template.

    As I noted the script you are starting from is bogus.  It is not how we build signatures.  It was copied from an old VBScript that was also incorrectly designed.


    \_(ツ)_/


    JRV,

    Thanks for the reply. I have modified the line that you suggested like:

    $MSWord = New-Object -com word.application

    $MSWord.Documents.Add("\\PRODFS01-VM\Templates\EmailSignature\NormalEmail.dotm")
    $MSWord.Documents.Open("$LocalSignaturePath\$SignatureName.docx")
    $MSWord.Selection.Font.Name = 'Verdana'

    Note: NormalEmail.dotm is blank file with the Consolas font Size 11.

    However, the email signature is still on Calibri in Outlook 2013 client.


    /* Server Support Specialist */


    Tuesday, May 8, 2018 5:44 AM
  • We place al of the text in the DOTM file and format it as needed.   Add fields where you want to insert text and name them.  All we do then is to set the fields values and crate the signature.

    Look in the Gallery for scripts that correctly create signatures.  There are many.  Find One that works as you like. 

    I cannot teach you how to use Word or PowerShell.  I can only suggest what you need to learn how to do and where to find examples.  The purpose of the forum is to answer specific questions about PowerShell and is not a place to learn how to program Word.


    \_(ツ)_/

    Tuesday, May 8, 2018 6:06 AM
    Moderator
  • We place al of the text in the DOTM file and format it as needed.   Add fields where you want to insert text and name them.  All we do then is to set the fields values and crate the signature.

    Look in the Gallery for scripts that correctly create signatures.  There are many.  Find One that works as you like. 

    I cannot teach you how to use Word or PowerShell.  I can only suggest what you need to learn how to do and where to find examples.  The purpose of the forum is to answer specific questions about PowerShell and is not a place to learn how to program Word.


    \_(ツ)_/

    Hi JRV,

    Suppose I have the below email template created by the marketing team:

    I believe the PowerShell script I am using is the easiest one to customize to replace the above document from AD attributes.

    It's just the Font typeface is really hard to change and set.

    Using other PowerShell script is too hard to translate or to convert the MSWord .DOCX above into HTML script encapsulated in the PowerShell.


    /* Server Support Specialist */

    Tuesday, May 8, 2018 7:16 AM
  • Once you have a complete template with all fields to be replace bookmarked you can then create a document and replace the named bookmarks with text.  Bookmarks cab be links or just formatted text.

    To replace the text by bookmark:

    $doc.Bookmarks['Email'].Range.Text = 'mymail.test.com'
    $doc.Bookmarks['FullName'].Range.Text = 'Jack C. Spratt'

    To assign the signature to Outlook.

    $wd.EmailOptions.EmailSignature.EmailSignatureEntries.Add('MySig1',$doc.Range()) $wd.EmailOptions.EmailSignature.NewMessageSignature = 'MySig1' $wd.EmailOptions.EmailSignature.ReplyMessageSignature = 'MySig1'

    All formatting will be retained according to the template.


    \_(ツ)_/



    Tuesday, May 8, 2018 7:34 AM
    Moderator
  • Here is the while signature creation script based on a template.  Templates can be stored on a share.

    # create word document
    $wd = New-Object -ComObject Word.Application
    $doc = $wd.Documents.Add('\\corp1\templates\Test\signature.dotx')
    #$wd.Visible = $true
    
    # set all bookmark texts by name
    $doc.Bookmarks['Email'].Range.Text = 'mymail.test.com'
    $doc.Bookmarks['Fullname'].Range.Text = 'Jack Spratt'
    
    # generate signatures in Outlook
    $wd.EmailOptions.EmailSignature.EmailSignatureEntries.Add('MySig1',$doc.Range())
    $wd.EmailOptions.EmailSignature.NewMessageSignature = 'MySig1'
    $wd.EmailOptions.EmailSignature.ReplyMessageSignature = 'MySig1'
    
    # abort document and close/quit
    $doc.Saved = $true
    $doc.Close()
    $wd.Quit()
    
    


    \_(ツ)_/

    Tuesday, May 8, 2018 7:45 AM
    Moderator
  • Here is the while signature creation script based on a template.  Templates can be stored on a share.

    # create word document
    $wd = New-Object -ComObject Word.Application
    $doc = $wd.Documents.Add('\\corp1\templates\Test\signature.dotx')
    #$wd.Visible = $true
    
    # set all bookmark texts by name
    $doc.Bookmarks['Email'].Range.Text = 'mymail.test.com'
    $doc.Bookmarks['Fullname'].Range.Text = 'Jack Spratt'
    
    # generate signatures in Outlook
    $wd.EmailOptions.EmailSignature.EmailSignatureEntries.Add('MySig1',$doc.Range())
    $wd.EmailOptions.EmailSignature.NewMessageSignature = 'MySig1'
    $wd.EmailOptions.EmailSignature.ReplyMessageSignature = 'MySig1'
    
    # abort document and close/quit
    $doc.Saved = $true
    $doc.Close()
    $wd.Quit()
    


    \_(ツ)_/

    OK, so basically:

    1. Create blank MS Word Doc template file.
    2. edit and insert the picture so that it looks like the below:

    The code will be adjusted:

    # create word document
    $wd = New-Object -ComObject Word.Application
    $doc = $wd.Documents.Add('\\corp1\templates\Test\signature.dotx')
    #$wd.Visible = $true
    
    # set all bookmark texts by name
    $doc.Bookmarks['AD_Email'].Range.Text = 'mymail.test.com'
    $doc.Bookmarks['AD_DisplayName'].Range.Text = 'Jack Spratt'
    ....
    
    # generate signatures in Outlook
    $wd.EmailOptions.EmailSignature.EmailSignatureEntries.Add('MySig1',$doc.Range())
    $wd.EmailOptions.EmailSignature.NewMessageSignature = 'MySig1'
    $wd.EmailOptions.EmailSignature.ReplyMessageSignature = 'MySig1'
    
    # abort document and close/quit
    $doc.Saved = $true
    $doc.Close()
    $wd.Quit()


    /* Server Support Specialist */

    Tuesday, May 8, 2018 7:50 AM
  • You have to create all of the named bookmarks.

    \_(ツ)_/

    Tuesday, May 8, 2018 7:52 AM
    Moderator
  • You have to create all of the named bookmarks.

    \_(ツ)_/

    Hi JRV,

    I got this error below and the Signature is not replacing the Variable in the Word Doc Template?

    Error:

             

    The requested member of the collection does not exist.
    + $doc.Bookmarks['ST_DisplayName'].Range.Text = $ADDisplayName
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : OperationStopped: (:) [], COMException
        + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException

    The requested member of the collection does not exist.
    + $doc.Bookmarks['ST_Title'].Range.Text = $ADTitle
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : OperationStopped: (:) [], COMException
        + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException

    The requested member of the collection does not exist.
    + $doc.Bookmarks['ST_City'].Range.Text = $ReplaceText
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : OperationStopped: (:) [], COMException
        + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException

    The requested member of the collection does not exist.
    + $doc.Bookmarks['ST_Telephone'].Range.Text = $ADTelePhoneNumber
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : OperationStopped: (:) [], COMException
        + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException

    The requested member of the collection does not exist.
    + $doc.Bookmarks['ST_MobilePhone'].Range.Text = $ADMobilePhone
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : OperationStopped: (:) [], COMException
        + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException


    Application : Microsoft.Office.Interop.Word.ApplicationClass
    Creator     : 1297307460
    Parent      : System.__ComObject
    Index       : 1
    Name        : Default Outlook Signature

    This is the modified source code:

    # create word document
    $WordDoc = New-Object -ComObject Word.Application
    $doc = $WordDoc.Documents.Add('\\Site1FS01-VM\EmailSignature\Default Outlook Signature.dotx')
    
    $props=@(
    	'company',
    	'l',
    	'displayname',
    	'mail',
    	'mobile',
    	'postalCode',
    	'streetAddress',
    	'st',
    	'title',
    	'telephonenumber'
    )
    $UserName = $env:username
    $searcher=[adsisearcher]"samAccountName=$($env:username)"
    $searcher.PropertiesToLoad.AddRange($props)
    $ADUser = $searcher.FindOne()
    
    $ADDisplayName = $ADUser.Properties['displayname']
    $ADEmailAddress = $ADUser.Properties['mail']
    $ADTitle = $ADUser.Properties['title']
    $ADTelePhoneNumber = $ADUser.Properties['telephonenumber']
    $ADMobilePhone = $ADUser.Properties['mobile']
    $ADStreetAddress = $ADUser.Properties['streetAddress']
    $ADCity = $ADUser.Properties['l']
    $ADState = $ADUser.Properties['st']
    $ADPostal = $ADUser.Properties['postalCode']
    
    If ($ADCity -ne '') {    
        switch ( $ADPostal ) {
            1234 { $ReplaceText = 'City 1'         }
            5678 { $ReplaceText = 'City 2'         }
            9999 { $ReplaceText = 'Rural'         }
    		default {$ReplaceText = ''}
        }
        $ReplaceText
       }
       Else {
        $ReplaceText = 'Please Update the user AD Attributes' 
       }
    
    # set all bookmark texts by name
    $doc.Bookmarks['ST_DisplayName'].Range.Text = $ADDisplayName
    $doc.Bookmarks['ST_Title'].Range.Text = $ADTitle
    $doc.Bookmarks['ST_City'].Range.Text = $ReplaceText
    $doc.Bookmarks['ST_Telephone'].Range.Text = $ADTelePhoneNumber
    $doc.Bookmarks['ST_MobilePhone'].Range.Text = $ADMobilePhone
    
    # generate signatures in Outlook
    $WordDoc.EmailOptions.EmailSignature.EmailSignatureEntries.Add('Default Outlook Signature',$doc.Range())
    $WordDoc.EmailOptions.EmailSignature.NewMessageSignature = 'Default Outlook Signature'
    $WordDoc.EmailOptions.EmailSignature.ReplyMessageSignature = 'Default Outlook Signature'
    
    # abort document and close/quit
    $doc.Saved = $true
    $doc.Close()
    $WordDoc.Quit()

    This is the content of .DOTX file:


    /* Server Support Specialist */



    Thursday, May 17, 2018 7:29 AM
  • You have to create the bookmarks in the template before you can use them.

    You must use my methods for creating the document.

    Please use only my code to test you bookmarks.  Look closely at it and try to understand how it works.

    To learn programming it is necessary to do only a small amount until you understand how the technology works. 


    \_(ツ)_/

    Thursday, May 17, 2018 7:41 AM
    Moderator
  • You have to create the bookmarks in the template before you can use them.

    You must use my methods for creating the document.

    Please use only my code to test you bookmarks.  Look closely at it and try to understand how it works.

    To learn programming it is necessary to do only a small amount until you understand how the technology works. 


    \_(ツ)_/

    JRV,

    Yes, the AD Attributes import code was from your thread that you reply a long time ago.

    I assume that:

    1. I must create and design the template layout first.
    2. name each AD Attributes variables and then highlight it and create it as Bookmark.
    3. run the PowerShell script so the AD Attributes is replacing the values according to the current users.


    /* Server Support Specialist */

    Thursday, May 17, 2018 12:56 PM