# HTML signature in EXOL for multiple users.

**URL:** <https://forums.powershell.org/t/html-signature-in-exol-for-multiple-users/3972>\
**Category:** PowerShell Help\
**Created:** [April 2, 2015, 8:36pm UTC](https://forums.powershell.org/t/html-signature-in-exol-for-multiple-users/3972 "2015-04-02T20:36:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![byeron89](https://avatars.discourse-cdn.com/v4/letter/b/ee7513/32.png) [@byeron89](https://forums.powershell.org/u/byeron89)\
**Post date:** [April 2, 2015, 8:36pm UTC](https://forums.powershell.org/t/html-signature-in-exol-for-multiple-users/3972/1 "2015-04-02T20:36:46Z")

</div>

Just trying to understand what is happening in the below cmdlet which was given to me by an engineer from Microsoft. slightly convoluted.  
As far as my understanding, it gets all mailboxes of type ‘UserMailbox’ and foreach file in path “C:\signatures” + (this is where i get confused).

```
Get-Mailbox -ResultSize unlimited -Filter {RecipientTypeDetails -eq 'UserMailbox'} | foreach{ $file= "C:\signatures\" + ($_.displayname) + ".htm"; Set-MailboxMessageConfiguration -identity $_.displayname -SignatureHtml "$(Get-Content -Path $file -ReadCount 0))"}
```

---

<div class="post-metadata">

**Author:** ![daniel-krebs](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/daniel-krebs/32/484_2.png) [@daniel-krebs](https://forums.powershell.org/u/daniel-krebs)\
**Post date:** [April 2, 2015, 10:13pm UTC](https://forums.powershell.org/t/html-signature-in-exol-for-multiple-users/3972/2 "2015-04-02T22:13:31Z")

</div>

Hi Byron,

I will attempt to explain what is happening and provide an alternative way to write the same (more script style).

1. You are right this will return all user mailboxes.

```
Get-Mailbox -ResultSize unlimited -Filter {RecipientTypeDetails -eq 'UserMailbox'}
```

1. The Get-Mailbox cmdlet will return objects for each mailbox which have properties like DisplayName, etc. Each object gets piped to the next cmdlet in the pipeline using the pipeline character (|).

2. foreach is the next cmdlet in your pipeline. foreach will receive one object at a time and process it in the script block provided { … }. An automatic variable $\_ is being made available during script block execution for you to access the object properties and methods.

```
foreach {

  $_ # Automatic variable. See https://technet.microsoft.com/en-us/library/hh847768.aspx
}
```

1. A couple of things are happening inside the scriptblock.

a. The DisplayName property of a mailbox will be accessed via the $\_ (automatic variable) and embedded into the string being constructed. The full string will be assigned to a temporary variable $file.

```
$file= "C:\signatures\" + ($_.displayname) + ".htm"
```

b. You can see the Get-Content cmdlet at the end. This read the HTM file specified in $file variable from the disk and will assign it to the SignatureHtml parameter of Set-MailboxMessageConfiguration before its invocation.

```
Set-MailboxMessageConfiguration -identity $_.displayname -SignatureHtml "$(Get-Content -Path $file -ReadCount 0))"
```

Alternative version as script:

```
$Mailboxes = Get-Mailbox -ResultSize unlimited -Filter { RecipientTypeDetails -eq 'UserMailbox' }

foreach ($Mailbox in $Mailboxes) {

    $File = "C:\signatures\" + ($Mailbox.DisplayName) + ".htm"
    $FileContent = Get-Content -Path $File -ReadCount 0
    Set-MailboxMessageConfiguration -Identity $Mailbox.DisplayName -SignatureHtml $FileContent
}
```

I hope above makes sense.

Regards  
Daniel

---

<div class="post-metadata">

**Author:** ![byeron89](https://avatars.discourse-cdn.com/v4/letter/b/ee7513/32.png) [@byeron89](https://forums.powershell.org/u/byeron89)\
**Post date:** [April 2, 2015, 11:11pm UTC](https://forums.powershell.org/t/html-signature-in-exol-for-multiple-users/3972/3 "2015-04-02T23:11:04Z")

</div>

Daniel, I really appreciate your help! your script is more comprehensive! would I be right in saying that I must name all the signature files using the DisplayName property value of each mailbox, respectively?

also is the line below basically adding the DisplayName property and file extension .htm to each file in the folder?

```
$File = "C:\signatures\" + ($Mailbox.DisplayName) + ".htm"
```

---

<div class="post-metadata">

**Author:** ![daniel-krebs](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/daniel-krebs/32/484_2.png) [@daniel-krebs](https://forums.powershell.org/u/daniel-krebs)\
**Post date:** [April 3, 2015, 3:00am UTC](https://forums.powershell.org/t/html-signature-in-exol-for-multiple-users/3972/4 "2015-04-03T03:00:17Z")

</div>

Hi Byron,

The script expects HTM files which match the DisplayName property which will most likely be Firstname Lastname.

```
PS C:\> Get-ChildItem C:\Signatures

    Directory: C:\Signatures

Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 03/04/2015 17:22 12 Byron Grogan.htm
-a---- 03/04/2015 17:22 12 Daniel Krebs.htm
```

The oneliner you have received from the Microsoft engineer did not check if the HTM file actually exists. I have updated the script to include a simple check using If and Test-Path.

```
$Mailboxes = Get-Mailbox -ResultSize unlimited -Filter { RecipientTypeDetails -eq 'UserMailbox' }
 
foreach ($Mailbox in $Mailboxes) {
 
    $File = "C:\signatures\" + ($Mailbox.DisplayName) + ".htm"
    if (Test-Path -Path $File) {

        $FileContent = Get-Content -Path $File -ReadCount 0
        Set-MailboxMessageConfiguration -Identity $Mailbox.DisplayName -SignatureHtml $FileContent
    }
}
```

I hope above answers your questions.

Regards  
Daniel

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:45pm UTC](https://forums.powershell.org/t/html-signature-in-exol-for-multiple-users/3972/5 "2024-05-16T20:45:32Z")

</div>


