chrisred / posh-scripts

11 stars 4 forks source link

OutlookSignatureScript.ps1 | additional code for running outlook process #10

Open Stonywall opened 3 years ago

Stonywall commented 3 years ago

When the script runs and Outlook is not open, it doesn't gracefully close Outlook after writing the new signature files.

I have made an addition to the code at the end to check if the process is interactive (the end user has Outlook open) or if it is "non-interactive" (the script opened it and there is no GUI interface). If it is "non-interactive", it will close all "Outlook" processes it finds, thus allowing the end user to launch Outlook.

Original Code

"@
    Write-Host $LogText
    if ($EnableLogFile) { Write-Log $LogText -EventId 1944 }

    if ($null -eq $Word)
    {
        # quit Word process if it was created and release from memory
        $Word.Quit() | Out-Null
        [System.Runtime.Interopservices.Marshal]::ReleaseComObject($Word) | Out-Null
        Remove-Variable -Name Word
    }

With New Code Addition

"@
    Write-Host $LogText
    if ($EnableLogFile) { Write-Log $LogText -EventId 1944 }

    if ($null -eq $Word)
    {
        # quit Word process if it was created and release from memory
        $Word.Quit() | Out-Null
        [System.Runtime.Interopservices.Marshal]::ReleaseComObject($Word) | Out-Null
        Remove-Variable -Name Word
    }

    # Check if outlook is open interactively
    if (Get-Process "Outlook")
    {
        try
        {
            [Runtime.Interopservices.Marshal]::GetActiveObject('Outlook.Application').ActiveWindow() | Out-Null
            $OutlookInteractive = $true
        }
        catch
        {
            $OutlookInteractive = $false
            Get-Process "Outlook" | Foreach-Object { Stop-Process $_ -force }
        }
    }
}
ajaigc commented 3 years ago

When attribute value is empty for example Tel. {Telephone} it can delete entire line?

chrisred commented 3 years ago

Hi @Stonywall, thanks for the code (sorry for the delayed reply!). When I was testing the Outlook process would close when the Word process was closed unless it had been opened already. But there maybe cases where this doesn't happen as you have seen. Checking if the Outlook window is active and then force closing seems like a good solution, ill try and test it out myself and update the script.

@ajaigc there is a variable in the script that does what you need, set $EnableDeleteEmptyTagLine to $true

ajaigc commented 3 years ago

Hi Chris,

Not exactly, Below is a sample of our signature template

{initials} {givenname} {sn} {title}

Tel. {telelphonnumber} | Cell {mobile} | {mail}

In this scenario when set $EnableDeleteEmptyTagLine to $true some users don’t want to show cell no in the signature then it removes complete line.

Also when {initials} is empty the text is not left aligned there is a blank space to the left.

With the help of a developer we modified a bit to meet our requirements

@.***D72EB5.32C6B300]

Sent from Mailhttps://go.microsoft.com/fwlink/?LinkId=550986 for Windows 10

From: Chris @.> Sent: 07 April 2021 03:10 To: @.> Cc: @.>; @.> Subject: Re: [chrisred/posh-scripts] OutlookSignatureScript.ps1 | additional code for running outlook process (#10)

Hi @Stonywallhttps://github.com/Stonywall, thanks for the code (sorry for the delayed reply!). When I was testing the Outlook process would close when the Word process was closed unless it had been opened already. But there maybe cases where this doesn't happen as you have seen. Checking if the Outlook window is active and then force closing seems like a good solution, ill try and test it out myself and update the script.

@ajaigchttps://github.com/ajaigc there is a variable in the script that does what you need, set $EnableDeleteEmptyTagLine to $true

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/chrisred/posh-scripts/issues/10#issuecomment-814456578, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ATL3ETEFKASCPXWRWDE7SKDTHN5WBANCNFSM4UV36DJA.