Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
4,035
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#
  2. .SYNOPSIS
  3. Sets your email signature according to company policy
  4.  
  5. .DESCRIPTION
  6. This script is designed to be run as a logon script, and it will create the proper files for the Outlook
  7. email signature in Outlook 2010/2013/2016. It executes an AD query, populates the proper fields, then pumps
  8. data into a word document which is saved as a rtf, txt, and htm. It then forcefully sets the registry settings
  9. so users cant change it.
  10. Requires:
  11. .INPUTS
  12. .OUTPUTS
  13. %appdata%\Microsoft\Signatures\v2.txt
  14. %appdata%\Microsoft\Signatures\v2.htm
  15. %appdata%\Microsoft\Signatures\v2.rtf
  16. %appdata%\Microsoft\Signatures\v2_files
  17. .NOTES
  18.   Version:        1.0
  19.   Author:         Buido.Signature@gmail.com
  20.   Creation Date:  11/11/2017
  21.   Purpose/Change:
  22. .EXAMPLE
  23. .ChangeLog
  24. #>
  25.  
  26. function Create-Log
  27. {
  28.     [cmdletbinding()]
  29.     param(
  30.  
  31.     [parameter(Mandatory=$true,
  32.             Position=0)]
  33.     [validatenotnullorempty()]
  34.     [string]$strComputerName
  35.     )
  36.  
  37.     $strLogLocation = Get-LogLocation -strComputerName $strComputerName
  38.     if ($(test-path $strLogLocation) -eq $false)
  39.     {
  40.         New-Item -Path $strLogLocation -ItemType File | Out-Null
  41.     }
  42. }
  43.  
  44. function Get-LogLocation
  45. {
  46.     [cmdletbinding()]
  47.     param(
  48.  
  49.     [parameter(Mandatory=$true,
  50.             Position=0)]
  51.     [validatenotnullorempty()]
  52.     [string]$strComputerName
  53.     )
  54.     if ($(test-path $($env:appdata + "\Email-SignatureScript")) -eq $false)
  55.     {
  56.         New-Item -Path $($env:appdata + "\Email-SignatureScript") -ItemType directory | Out-Null
  57.     }
  58.  
  59.     $strLogLocation = $env:appdata + "\Email-SignatureScript\" + $strComputerName + ".txt"
  60.     Return $strLogLocation
  61. }
  62.  
  63. function Log-This
  64. {
  65.     [cmdletbinding()]
  66.     param(
  67.  
  68.     [parameter(Mandatory=$true,
  69.             Position=0)]
  70.     [validatenotnullorempty()]
  71.     [string]$strLogLocation,
  72.  
  73.     [parameter(Mandatory=$true,
  74.             Position=0)]
  75.     [validatenotnullorempty()]
  76.     [string]$strErrorMessage
  77.     )
  78.  
  79.     ac -path $strLogLocation -Value "$strErrorMessage on $(get-date)"
  80. }
  81.  
  82. function Set-CompanyInfo
  83. {
  84.     [cmdletbinding()]
  85.     param(
  86.  
  87.     [parameter(Mandatory=$true,
  88.             Position=0)]
  89.     [validatenotnullorempty()]
  90.     [string]$strLogLocation,
  91.  
  92.     [parameter(Mandatory=$true,
  93.             Position=1)]
  94.     [validatenotnullorempty()]
  95.     [string]$strADCompany
  96.     )
  97.     try
  98.     {
  99.         $objCompanyDetails = New-Object System.Object
  100.         $objHyperlink = "www.google.com", "https://www.Google.com"
  101.         $strPicture = "$env:appdata\Microsoft\Stationery\google.png"
  102.         $Signame = "google Signature v1"
  103.  
  104.         Switch -regex ($strADCompany)
  105.         {
  106.             "\b(Google)\b"
  107.             {
  108.              
  109.                 $objHyperlink = "www.google.com", "https://www.Google.com"
  110.                 $strPicture = "$env:appdata\Microsoft\Stationery\google.png"
  111.                 $Signame = "google Signature v1"
  112.             }
  113.             "\b(Apple)\b"
  114.             {
  115.                 $objHyperlink = "http://www.Apple.com", "www.Apple.com"
  116.                 $strPicture = "$env:appdata\Microsoft\Stationery\Apple.png"
  117.                 $Signame = "Apple Signature v1"
  118.             }
  119.             "\b(Amazon)\b"
  120.             {
  121.                 $objHyperlink = "http://www.Amazon.com", "www.Amazon.com"
  122.                 $strPicture = "$env:appdata\Microsoft\Stationery\Amazon.png"
  123.                 $Signame = "Amazon Signature v1"
  124.             }
  125.             "\b(Microsoft)\b"
  126.             {
  127.                 $objHyperlink = "http://www.Microsoft.com", "www.Microsoft.com"
  128.                 $strPicture = "$env:appdata\Microsoft\Stationery\Microsoft.png"
  129.                 $Signame = "Microsoft Signature v1"
  130.             }
  131.             default {}
  132.         }
  133.  
  134.         $objCompanyDetails | Add-Member -MemberType NoteProperty -Name "Hyperlink" -Value $objHyperlink
  135.         $objCompanyDetails | Add-Member -MemberType NoteProperty -Name "Picture" -Value $strPicture
  136.         $objCompanyDetails | Add-Member -MemberType NoteProperty -Name "Signame" -Value $Signame
  137.     }
  138.     catch
  139.     {
  140.         $errItemName = $_.Exception.ItemName
  141.         Log-This -strLogLocation $strLogLocation -strErrorMessage "$errItemName - $_"
  142.     }
  143.  
  144.     Return $objCompanyDetails
  145. }
  146.  
  147. function Set-CountryInfo
  148. {
  149.     [cmdletbinding()]
  150.     param(
  151.  
  152.     [parameter(Mandatory=$true,
  153.             Position=0)]
  154.     [validatenotnullorempty()]
  155.     [string]$strLogLocation,
  156.  
  157.     [parameter(Mandatory=$true,
  158.             Position=1)]
  159.     [validatenotnullorempty()]
  160.     [string]$strCountry,
  161.  
  162.     [parameter(Mandatory=$true,
  163.             Position=1)]
  164.     [validatenotnullorempty()]
  165.     [string]$strADCompany
  166.     )
  167.     try
  168.     {
  169.         $objCountryDetails = New-Object System.Object
  170.         $intFontSize = $null
  171.         $strLine1 = $null
  172.         $strLine1 = $null
  173.  
  174.         Switch ($strCountry)
  175.         {
  176.             "United Kingdom"
  177.             {
  178.                 if ($strADCompany -match "\b(google)\b" -or $strADCompany -match "\b(Google)\b")
  179.                 {
  180.                     $intFontSize = 8
  181.                     $strLine1 = "COMPANY NAME Registered in Scotland number #######. Registered office address: ############ $nl"
  182.                     $strLine2 = "Company Name Is a subsidiary of Company Name"
  183.                 }
  184.                 elseif ($strADCompany -match "\b(Amazon\b")
  185.                 {
  186.                     $intFontSize = 8
  187.                     $strLine1 = "COMPANY NAME Registered in Scotland number #######. Registered office address: ############ $nl"
  188.                     $strLine2 = "Company Name Is a subsidiary of Company Name"
  189.                 }
  190.             }
  191.             "Australia"
  192.             {
  193.                 $intFontSize = 8
  194.                 $strLine1 = "COMPANY NAME Registered in Australia. Registered office address: ADDRESS$nl"
  195.                 $strLine2 = "Company Name. Is a subsidiary of Company Name"
  196.             }
  197.             "Canada"
  198.             {
  199.                 $intFontSize = 8
  200.                 $strLine1 = "Registered in Canada. Registered office address: ADDRESS $nl"
  201.                 $strLine2 = "Company Name Is a subsidiary of Company Name."
  202.             }
  203.             default {}
  204.         }
  205.  
  206.         $objCountryDetails | Add-Member -MemberType NoteProperty -Name "FontSize" -Value $intFontSize
  207.         $objCountryDetails | Add-Member -MemberType NoteProperty -Name "Line1" -Value $strLine1
  208.         $objCountryDetails | Add-Member -MemberType NoteProperty -Name "Line2" -Value $strLine2
  209.     }
  210.     catch
  211.     {
  212.         $errItemName = $_.Exception.ItemName
  213.         Log-This -strLogLocation $strLogLocation -strErrorMessage "$errItemName - $_"
  214.     }
  215.  
  216.     if ( $intFontSize -eq $null)
  217.     {
  218.         $objCountryDetails = $null
  219.     }
  220.     Return $objCountryDetails
  221. }
  222.  
  223. function Add-Name
  224. {
  225.     [cmdletbinding()]
  226.     param(
  227.  
  228.     [parameter(Mandatory=$true,
  229.             Position=0)]
  230.     [validatenotnullorempty()]
  231.     [string]$strLogLocation,
  232.  
  233.     [parameter(Mandatory=$true,
  234.             Position=1)]
  235.     [validatenotnullorempty()]
  236.     $objSelection,
  237.  
  238.     [parameter(Mandatory=$true,
  239.             Position=2)]
  240.     [validatenotnullorempty()]
  241.     [string]$strADDisplayName,
  242.  
  243.     [parameter(Mandatory=$true,
  244.             Position=3)]
  245.     [validatenotnullorempty()]
  246.     $objNameStyle
  247.     )
  248.  
  249.     try
  250.     {
  251.         $objSelection.ParagraphFormat.SpaceAfter = 0
  252.         $objSelection.ParagraphFormat.SpaceBefore = 0
  253.         if ($objNameStyle.Size -ne $null)
  254.         {
  255.             $objSelection.Font.Size = $objNameStyle.Size
  256.         }
  257.         if ($objNameStyle.Bold -ne $null)
  258.         {
  259.             $objSelection.Font.Bold = $objNameStyle.Bold
  260.         }
  261.         if ($objNameStyle.Italic -ne $null)
  262.         {
  263.             $objSelection.Font.Italic = $objNameStyle.Italic
  264.         }
  265.         if ($objNameStyle.Color -ne $null)
  266.         {
  267.             $objSelection.Font.Color = $objNameStyle.Color
  268.         }
  269.         if ($objNameStyle.Name -ne $null)
  270.         {
  271.             $objSelection.Font.Name = $objNameStyle.Name
  272.         }
  273.         $objSelection.TypeText($strADDisplayName)
  274.         $objSelection.TypeParagraph()
  275.     }
  276.     catch
  277.     {
  278.         $errItemName = $_.Exception.ItemName
  279.         Log-This -strLogLocation $strLogLocation -strErrorMessage "$errItemName - $_"
  280.     }
  281.  
  282.     Return $objSelection
  283. }
  284.  
  285. function Add-Title
  286. {
  287.     [cmdletbinding()]
  288.     param(
  289.  
  290.     [parameter(Mandatory=$true,
  291.             Position=0)]
  292.     [validatenotnullorempty()]
  293.     [string]$strLogLocation,
  294.  
  295.     [parameter(Mandatory=$true,
  296.             Position=1)]
  297.     [validatenotnullorempty()]
  298.     $objSelection,
  299.  
  300.     [parameter(Mandatory=$true,
  301.             Position=2)]
  302.     [validatenotnullorempty()]
  303.     [string]$strADTitle,
  304.  
  305.     [parameter(Mandatory=$true,
  306.             Position=3)]
  307.     [validatenotnullorempty()]
  308.     $objTitleStyle
  309.     )
  310.  
  311.      try
  312.     {
  313.         if ($objTitleStyle.Size -ne $null)
  314.         {
  315.             $objSelection.Font.Size = $objTitleStyle.Size
  316.         }
  317.         if ($objTitleStyle.Bold -ne $null)
  318.         {
  319.             $objSelection.Font.Bold = $objTitleStyle.Bold
  320.         }
  321.         if ($objTitleStyle.Italic -ne $null)
  322.         {
  323.             $objSelection.Font.Italic = $objTitleStyle.Italic
  324.         }
  325.         if ($objTitleStyle.Color -ne $null)
  326.         {
  327.             $objSelection.Font.Color = $objTitleStyle.Color
  328.         }
  329.         if ($objTitleStyle.Name -ne $null)
  330.         {
  331.             $objSelection.Font.Name = $objTitleStyle.Name
  332.         }
  333.         $objSelection.TypeText($strADTitle)
  334.         $objSelection.TypeParagraph()
  335.     }
  336.     catch
  337.     {
  338.         $errItemName = $_.Exception.ItemName
  339.         Log-This -strLogLocation $strLogLocation -strErrorMessage "$errItemName - $_"
  340.     }
  341.  
  342.     Return $objSelection
  343. }
  344.  
  345. function Add-Tel
  346. {
  347.     [cmdletbinding()]
  348.     param(
  349.  
  350.     [parameter(Mandatory=$true,
  351.             Position=0)]
  352.     [validatenotnullorempty()]
  353.     [string]$strLogLocation,
  354.  
  355.     [parameter(Mandatory=$true,
  356.             Position=1)]
  357.     [validatenotnullorempty()]
  358.     $objSelection,
  359.  
  360.     [parameter(Mandatory=$true,
  361.             Position=2)]
  362.     [validatenotnullorempty()]
  363.     [string]$strADTelePhoneNumber,
  364.  
  365.     [parameter(Mandatory=$true,
  366.             Position=3)]
  367.     [validatenotnullorempty()]
  368.     $objTelStyle
  369.     )
  370.  
  371.      try
  372.     {
  373.         if ($objTelStyle.Size -ne $null)
  374.         {
  375.             $objSelection.Font.Size = $objTelStyle.Size
  376.         }
  377.         if ($objTelStyle.Bold -ne $null)
  378.         {
  379.             $objSelection.Font.Bold = $objTelStyle.Bold
  380.         }
  381.         if ($objTelStyle.Italic -ne $null)
  382.         {
  383.             $objSelection.Font.Italic = $objTelStyle.Italic
  384.         }
  385.         if ($objTelStyle.Color -ne $null)
  386.         {
  387.             $objSelection.Font.Color = $objTelStyle.Color
  388.         }
  389.         if ($objTelStyle.Name -ne $null)
  390.         {
  391.             $objSelection.Font.Name = $objTelStyle.Name
  392.         }
  393.         $objSelection.TypeText("Tel: $strADTelePhoneNumber")
  394.         $objSelection.TypeParagraph()
  395.     }
  396.     catch
  397.     {
  398.         $errItemName = $_.Exception.ItemName
  399.         Log-This -strLogLocation $strLogLocation -strErrorMessage "$errItemName - $_"
  400.     }
  401.  
  402.     Return $objSelection
  403. }
  404. function Add-Tel2
  405. {
  406.     [cmdletbinding()]
  407.     param(
  408.  
  409.     [parameter(Mandatory=$true,
  410.             Position=0)]
  411.     [validatenotnullorempty()]
  412.     [string]$strLogLocation,
  413.  
  414.     [parameter(Mandatory=$true,
  415.             Position=1)]
  416.     [validatenotnullorempty()]
  417.     $objSelection,
  418.  
  419.     [parameter(Mandatory=$true,
  420.             Position=2)]
  421.     [validatenotnullorempty()]
  422.     [string]$strADTelePhoneNumber2,
  423.  
  424.     [parameter(Mandatory=$true,
  425.             Position=3)]
  426.     [validatenotnullorempty()]
  427.     $objTelStyle
  428.     )
  429.  
  430.      try
  431.     {
  432.         if ($objTelStyle.Size -ne $null)
  433.         {
  434.             $objSelection.Font.Size = $objTelStyle.Size
  435.         }
  436.         if ($objTelStyle.Bold -ne $null)
  437.         {
  438.             $objSelection.Font.Bold = $objTelStyle.Bold
  439.         }
  440.         if ($objTelStyle.Italic -ne $null)
  441.         {
  442.             $objSelection.Font.Italic = $objTelStyle.Italic
  443.         }
  444.         if ($objTelStyle.Color -ne $null)
  445.         {
  446.             $objSelection.Font.Color = $objTelStyle.Color
  447.         }
  448.         if ($objTelStyle.Name -ne $null)
  449.         {
  450.             $objSelection.Font.Name = $objTelStyle.Name
  451.         }
  452.         $objSelection.TypeText("Tel: $strADTelePhoneNumber")
  453.         $objSelection.TypeParagraph()
  454.     }
  455.     catch
  456.     {
  457.         $errItemName = $_.Exception.ItemName
  458.         Log-This -strLogLocation $strLogLocation -strErrorMessage "$errItemName - $_"
  459.     }
  460.  
  461.     Return $objSelection
  462. }
  463.  
  464. function Add-Mobile
  465. {
  466.     [cmdletbinding()]
  467.     param(
  468.  
  469.     [parameter(Mandatory=$true,
  470.             Position=0)]
  471.     [validatenotnullorempty()]
  472.     [string]$strLogLocation,
  473.  
  474.     [parameter(Mandatory=$true,
  475.             Position=1)]
  476.     [validatenotnullorempty()]
  477.     $objSelection,
  478.  
  479.     [parameter(Mandatory=$true,
  480.             Position=2)]
  481.     [validatenotnullorempty()]
  482.     [string]$strADMobile,
  483.  
  484.     [parameter(Mandatory=$true,
  485.             Position=3)]
  486.     [validatenotnullorempty()]
  487.     $objMobileStyle
  488.     )
  489.  
  490.      try
  491.     {
  492.         if ($objMobileStyle.Size -ne $null)
  493.         {
  494.             $objSelection.Font.Size = $objMobileStyle.Size
  495.         }
  496.         if ($objMobileStyle.Bold -ne $null)
  497.         {
  498.             $objSelection.Font.Bold = $objMobileStyle.Bold
  499.         }
  500.         if ($objMobileStyle.Italic -ne $null)
  501.         {
  502.             $objSelection.Font.Italic = $objMobileStyle.Italic
  503.         }
  504.         if ($objMobileStyle.Color -ne $null)
  505.         {
  506.             $objSelection.Font.Color = $objMobileStyle.Color
  507.         }
  508.         if ($objMobileStyle.Name -ne $null)
  509.         {
  510.             $objSelection.Font.Name = $objMobileStyle.Name
  511.         }
  512.         $objSelection.TypeText("Mob: $strADMobile")
  513.         $objSelection.TypeParagraph()
  514.     }
  515.     catch
  516.     {
  517.         $errItemName = $_.Exception.ItemName
  518.         Log-This -strLogLocation $strLogLocation -strErrorMessage "$errItemName - $_"
  519.     }
  520.  
  521.     Return $objSelection
  522. }
  523. function Add-Mobile2
  524. {
  525.     [cmdletbinding()]
  526.     param(
  527.  
  528.     [parameter(Mandatory=$true,
  529.             Position=0)]
  530.     [validatenotnullorempty()]
  531.     [string]$strLogLocation,
  532.  
  533.     [parameter(Mandatory=$true,
  534.             Position=1)]
  535.     [validatenotnullorempty()]
  536.     $objSelection,
  537.  
  538.     [parameter(Mandatory=$true,
  539.             Position=2)]
  540.     [validatenotnullorempty()]
  541.     [string]$strADMobile2,
  542.  
  543.     [parameter(Mandatory=$true,
  544.             Position=3)]
  545.     [validatenotnullorempty()]
  546.     $objMobileStyle
  547.     )
  548.  
  549.      try
  550.     {
  551.         if ($objMobileStyle.Size -ne $null)
  552.         {
  553.             $objSelection.Font.Size = $objMobileStyle.Size
  554.         }
  555.         if ($objMobileStyle.Bold -ne $null)
  556.         {
  557.             $objSelection.Font.Bold = $objMobileStyle.Bold
  558.         }
  559.         if ($objMobileStyle.Italic -ne $null)
  560.         {
  561.             $objSelection.Font.Italic = $objMobileStyle.Italic
  562.         }
  563.         if ($objMobileStyle.Color -ne $null)
  564.         {
  565.             $objSelection.Font.Color = $objMobileStyle.Color
  566.         }
  567.         if ($objMobileStyle.Name -ne $null)
  568.         {
  569.             $objSelection.Font.Name = $objMobileStyle.Name
  570.         }
  571.         $objSelection.TypeText("Mob: $strADMobile2")
  572.         $objSelection.TypeParagraph()
  573.     }
  574.     catch
  575.     {
  576.         $errItemName = $_.Exception.ItemName
  577.         Log-This -strLogLocation $strLogLocation -strErrorMessage "$errItemName - $_"
  578.     }
  579.  
  580.     Return $objSelection
  581. }
  582.  
  583. function Add-Fax
  584. {
  585.     [cmdletbinding()]
  586.     param(
  587.  
  588.     [parameter(Mandatory=$true,
  589.             Position=0)]
  590.     [validatenotnullorempty()]
  591.     [string]$strLogLocation,
  592.  
  593.     [parameter(Mandatory=$true,
  594.             Position=1)]
  595.     [validatenotnullorempty()]
  596.     $objSelection,
  597.  
  598.     [parameter(Mandatory=$true,
  599.             Position=2)]
  600.     [validatenotnullorempty()]
  601.     [string]$strADFax,
  602.  
  603.     [parameter(Mandatory=$true,
  604.             Position=3)]
  605.     [validatenotnullorempty()]
  606.     $objFaxStyle
  607.     )
  608.  
  609.      try
  610.     {
  611.         if ($objFaxStyle.Size -ne $null)
  612.         {
  613.             $objSelection.Font.Size = $objFaxStyle.Size
  614.         }
  615.         if ($objFaxStyle.Bold -ne $null)
  616.         {
  617.             $objSelection.Font.Bold = $objFaxStyle.Bold
  618.         }
  619.         if ($objFaxStyle.Italic -ne $null)
  620.         {
  621.             $objSelection.Font.Italic = $objFaxStyle.Italic
  622.         }
  623.         if ($objFaxStyle.Color -ne $null)
  624.         {
  625.             $objSelection.Font.Color = $objFaxStyle.Color
  626.         }
  627.         if ($objFaxStyle.Name -ne $null)
  628.         {
  629.             $objSelection.Font.Name = $objFaxStyle.Name
  630.         }
  631.         $objSelection.TypeText("Fax: $strADFax")
  632.         $objSelection.TypeParagraph()
  633.     }
  634.     catch
  635.     {
  636.         $errItemName = $_.Exception.ItemName
  637.         Log-This -strLogLocation $strLogLocation -strErrorMessage "$errItemName - $_"
  638.     }
  639.  
  640.     Return $objSelection
  641. }
  642.  
  643. function Add-CompanySpecific
  644. {
  645.     [cmdletbinding()]
  646.     param(
  647.  
  648.     [parameter(Mandatory=$true,
  649.             Position=0)]
  650.     [validatenotnullorempty()]
  651.     [string]$strLogLocation,
  652.  
  653.     [parameter(Mandatory=$true,
  654.             Position=1)]
  655.     [validatenotnullorempty()]
  656.     $objSelection,
  657.  
  658.     [parameter(Mandatory=$true,
  659.             Position=2)]
  660.     [validatenotnullorempty()]
  661.     $objDocument,
  662.  
  663.     [parameter(Mandatory=$true,
  664.             Position=3)]
  665.     [validatenotnullorempty()]
  666.     $objCompanyInfo,
  667.  
  668.     [parameter(Mandatory=$true,
  669.             Position=4)]
  670.     [validatenotnullorempty()]
  671.     [int]$intPSVersion,
  672.  
  673.     [parameter(Mandatory=$true,
  674.             Position=5)]
  675.     $objBanner,
  676.  
  677.     [parameter(Mandatory=$true,
  678.             Position=5)]
  679.     $bolBanner
  680.    
  681.     )
  682.     try
  683.     {
  684.         ##$objLink = $objDocument.Hyperlinks.Add($objSelection,$objCompanyInfo.Hyperlink[1],$null,$null,$objCompanyInfo.Hyperlink[0])
  685.         if ($intPSVersion -eq 2)
  686.         {
  687.             $objRange = $objSelection.Range
  688.             $objDocument.Hyperlinks.Add($objRange, $objCompanyInfo.Hyperlink[1], $False, $False, $objCompanyInfo.Hyperlink[0])
  689.             $objSelection.TypeParagraph()
  690.             $objSelection.InlineShapes.AddPicture($objCompanyInfo.Picture)
  691.             $objSelection.TypeParagraph()
  692.             if ($bolBanner -eq $true)
  693.             {
  694.                 ##Email Signature addition as per ticket #29851
  695.                 if ($objBanner.banners -ne $null -and $(get-date) -lt $objBanner.End_Date -and $(get-date) -gt $objBanner.Start_Date)
  696.                 {
  697.                     $objSelection.InlineShapes.AddPicture($objBanner.File_Location)
  698.                     $objSelection.TypeParagraph()
  699.                 }
  700.             }
  701.         }
  702.         else
  703.         {
  704.             $objRange = $objSelection.Range()
  705.             $objDocument.Hyperlinks.Add($objRange, $objCompanyInfo.Hyperlink[1], $False, $False, $objCompanyInfo.Hyperlink[0])
  706.             $objSelection.TypeParagraph()
  707.             $objSelection.InlineShapes.AddPicture($objCompanyInfo.Picture)
  708.             $objSelection.TypeParagraph()
  709.             ##Email Signature addition as per ticket #29851
  710.             if ($bolBanner -eq $true)
  711.             {
  712.                 if ($objBanner.banners -ne $null -and $(get-date) -lt $objBanner.End_Date -and $(get-date) -gt $objBanner.Start_Date)
  713.                 {
  714.                     $objSelection.InlineShapes.AddPicture($objBanner.File_Location)
  715.                     $objSelection.TypeParagraph()
  716.                 }
  717.             }
  718.         }
  719.     }
  720.     catch
  721.     {
  722.         $errItemName = $_.Exception.ItemName
  723.         Log-This -strLogLocation $strLogLocation -strErrorMessage "$errItemName - $_"
  724.         Log-This -strLogLocation $strLogLocation -strErrorMessage "$intPSVersion"
  725.     }
  726.     Return $objSelection
  727. }
  728.  
  729. function Add-ARInfo
  730. {
  731.     [cmdletbinding()]
  732.     param(
  733.  
  734.     [parameter(Mandatory=$true,
  735.             Position=0)]
  736.     [validatenotnullorempty()]
  737.     [string]$strLogLocation,
  738.  
  739.     [parameter(Mandatory=$true,
  740.             Position=1)]
  741.     [validatenotnullorempty()]
  742.     $objSelection,
  743.  
  744.     [parameter(Mandatory=$true,
  745.             Position=2)]
  746.     [validatenotnullorempty()]
  747.     $objArStyle
  748.     )
  749.     try
  750.     {
  751.         if ($objArStyle.Size -ne $null)
  752.         {
  753.             $objSelection.Font.Size = $objArStyle.Size
  754.         }
  755.         if ($objArStyle.Bold -ne $null)
  756.         {
  757.             $objSelection.Font.Bold = $objArStyle.Bold
  758.         }
  759.         if ($objArStyle.Italic -ne $null)
  760.         {
  761.             $objSelection.Font.Italic = $objArStyle.Italic
  762.         }
  763.         if ($objArStyle.Color -ne $null)
  764.         {
  765.             $objSelection.Font.Color = $objArStyle.Color
  766.         }
  767.         if ($objArStyle.Name -ne $null)
  768.         {
  769.             $objSelection.Font.Name = $objArStyle.Name
  770.         }
  771.         $objSelection.TypeText("Please remit all payments to: ")
  772.         $objSelection.TypeParagraph()
  773.         $objSelection.TypeText("**Company Name**")
  774.         $objSelection.TypeParagraph()
  775.         $objSelection.TypeText("**Second Line**")
  776.         $objSelection.TypeParagraph()
  777.         $objSelection.TypeText("PO BOX ******")
  778.         $objSelection.TypeParagraph()
  779.         $objSelection.TypeText("City, State ZIP")
  780.         $objSelection.TypeParagraph()
  781.     }
  782.     catch
  783.     {
  784.         $errItemName = $_.Exception.ItemName
  785.         Log-This -strLogLocation $strLogLocation -strErrorMessage "$errItemName - $_"
  786.     }
  787.     Return $objSelection
  788. }
  789.  
  790. function Add-CountrySpecific
  791. {
  792.     [cmdletbinding()]
  793.     param(
  794.  
  795.     [parameter(Mandatory=$true,
  796.             Position=0)]
  797.     [validatenotnullorempty()]
  798.     [string]$strLogLocation,
  799.  
  800.     [parameter(Mandatory=$true,
  801.             Position=1)]
  802.     [validatenotnullorempty()]
  803.     $objSelection,
  804.  
  805.     [parameter(Mandatory=$true,
  806.             Position=2)]
  807.     [validatenotnullorempty()]
  808.     $objCountryStyle,
  809.  
  810.     [parameter(Mandatory=$true,
  811.             Position=3)]
  812.     [validatenotnullorempty()]
  813.     $objCountryInfo
  814.     )
  815.     try
  816.     {
  817.         if ($objCountryStyle.Size -ne $null)
  818.         {
  819.             $objSelection.Font.Size = [Int]$objCountryStyle.Size
  820.         }
  821.         if ($objCountryStyle.Bold -ne $null)
  822.         {
  823.             $objSelection.Font.Bold = $objCountryStyle.Bold
  824.         }
  825.         if ($objCountryStyle.Italic -ne $null)
  826.         {
  827.             $objSelection.Font.Italic = $objCountryStyle.Italic
  828.         }
  829.         if ($objCountryStyle.Color -ne $null)
  830.         {
  831.             $objSelection.Font.Color = $objCountryStyle.Color
  832.         }
  833.         if ($objCountryStyle.Name -ne $null)
  834.         {
  835.             $objSelection.Font.Name = $objCountryStyle.Name
  836.         }
  837.         $objSelection.TypeText($objCountryInfo.Line1)
  838.         $objSelection.TypeText($objCountryInfo.Line2)
  839.         $objSelection.TypeParagraph()
  840.     }
  841.     catch
  842.     {
  843.         $errItemName = $_.Exception.ItemName
  844.         Log-This -strLogLocation $strLogLocation -strErrorMessage "Company Object: $errItemName - $_"
  845.         Log-This -strLogLocation $strLogLocation -strErrorMessage "$($objSelection.Font.Size)"
  846.         Log-This -strLogLocation $strLogLocation -strErrorMessage "$($objCountryStyle.Size)"
  847.     }
  848.     Return $objSelection
  849. }
  850.  
  851. function Create-StyleObject
  852. {
  853.     [cmdletbinding()]
  854.     param(
  855.  
  856.     [parameter(Mandatory=$true,
  857.             Position=0)]
  858.     [validatenotnullorempty()]
  859.     [string]$strLogLocation,
  860.  
  861.     [parameter(Mandatory=$true,
  862.             Position=1)]
  863.     [validatenotnullorempty()]
  864.     $intFontSize,
  865.  
  866.     [parameter(Mandatory=$true,
  867.             Position=2)]
  868.     [AllowNull()]
  869.     $intBold,
  870.  
  871.     [parameter(Mandatory=$true,
  872.             Position=3)]
  873.     [AllowNull()]
  874.     $intItalic,
  875.  
  876.     [parameter(Mandatory=$true,
  877.             Position=4)]
  878.     [AllowNull()]
  879.     $strColor,
  880.  
  881.     [parameter(Mandatory=$true,
  882.             Position=5)]
  883.     [AllowNull()]
  884.     $strName
  885.     )
  886.  
  887.     $objStyleInfo = New-Object System.Object
  888.     try
  889.     {
  890.         $objStyleInfo | Add-Member -MemberType NoteProperty -Name "Size" -Value $intFontSize
  891.         $objStyleInfo | Add-Member -MemberType NoteProperty -Name "Bold" -Value $intBold
  892.         $objStyleInfo | Add-Member -MemberType NoteProperty -Name "Italic" -Value $intItalic
  893.         $objStyleInfo | Add-Member -MemberType NoteProperty -Name "Color" -Value $strColor
  894.         $objStyleInfo | Add-Member -MemberType NoteProperty -Name "Name" -Value $strName
  895.     }
  896.     catch
  897.     {
  898.         $errItemName = $_.Exception.ItemName
  899.         Log-This -strLogLocation $strLogLocation -strErrorMessage "Style Object: $errItemName - $_"
  900.     }
  901.  
  902.     Return $objStyleInfo
  903.  
  904. }
  905.  
  906. function Remove-ComObject
  907. {
  908.     [cmdletbinding()]
  909.     param(
  910.  
  911.     [parameter(Mandatory=$true,
  912.             Position=0)]
  913.     [validatenotnullorempty()]
  914.     [string]$strLogLocation,
  915.  
  916.     [parameter(Mandatory=$true,
  917.             Position=1)]
  918.     [validatenotnullorempty()]
  919.     $comMSWord
  920.     )
  921.  
  922.     try
  923.     {
  924.     [System.Runtime.InteropServices.Marshal]::ReleaseComObject([System.__ComObject]$comMSWord) | Out-Null
  925.     [gc]::Collect()
  926.     [gc]::WaitForPendingFinalizers()
  927.     Remove-Variable comMSWord
  928.     }
  929.     catch
  930.     {
  931.         $errItemName = $_.Exception.ItemName
  932.         Log-This -strLogLocation $strLogLocation -strErrorMessage "$errItemName - $_"
  933.     }
  934.  
  935. }
  936.  
  937. function Create-InfoObject
  938. {
  939. [cmdletbinding()]
  940.     param(
  941.  
  942.     [parameter(Mandatory=$true,
  943.             Position=0)]
  944.     [validatenotnullorempty()]
  945.     [string]$strLogLocation,
  946.  
  947.     [parameter(Mandatory=$true,
  948.             Position=1)]
  949.     [validatenotnullorempty()]
  950.     [string]$strADDisplayName,
  951.  
  952.     [parameter(
  953.             Position=2)]
  954.     [validatenotnullorempty()]
  955.     [string]$strADTitle,
  956.  
  957.     [parameter(
  958.             Position=3)]
  959.     $strADTelePhoneNumber,
  960.  
  961.     [parameter(
  962.             Position=4)]
  963.     $strADTelePhoneNumber2,
  964.  
  965.     [parameter(
  966.             Position=5)]
  967.     $strADMobile,
  968.  
  969.     [parameter(
  970.             Position=6)]
  971.     $strADMobile2,
  972.  
  973.     [parameter(
  974.             Position=7)]
  975.     $strADCompany,
  976.  
  977.     [parameter(
  978.             Position=8)]
  979.     $strDepartment,
  980.  
  981.     [parameter(
  982.             Position=9)]
  983.     $strFax,
  984.  
  985.     [parameter(
  986.             Position=10)]
  987.     $strARCar,
  988.  
  989.     [parameter(
  990.             Position=11)]
  991.     $strCountry,
  992.  
  993.     [parameter(
  994.             Position=12)]
  995.     $strImage,
  996.  
  997.     [parameter(Mandatory=$true,
  998.             Position=13)]
  999.     [string]$strInfoLogLocation,
  1000.  
  1001.     [parameter(Mandatory=$true,
  1002.             Position=14)]
  1003.     [boolean]$Banner
  1004.  
  1005.     )
  1006.  
  1007.     $objInfo = New-Object System.Object
  1008.     try
  1009.     {
  1010.         $objInfo | Add-Member -MemberType NoteProperty -Name "DisplayName" -Value $strADDisplayName
  1011.         $objInfo | Add-Member -MemberType NoteProperty -Name "Title" -Value $strADTitle
  1012.         $objInfo | Add-Member -MemberType NoteProperty -Name "Tel1" -Value $strADTelePhoneNumber.Value
  1013.         $objInfo | Add-Member -MemberType NoteProperty -Name "Tel2" -Value $strADTelePhoneNumber2.Value
  1014.         $objInfo | Add-Member -MemberType NoteProperty -Name "Mob" -Value $strADMobile.Value
  1015.         $objInfo | Add-Member -MemberType NoteProperty -Name "Mob2" -Value $strADMobile2.Value
  1016.         $objInfo | Add-Member -MemberType NoteProperty -Name "Company" -Value $strADCompany.Value
  1017.         $objInfo | Add-Member -MemberType NoteProperty -Name "Department" -Value $strDepartment.Value
  1018.         $objInfo | Add-Member -MemberType NoteProperty -Name "Fax" -Value $strFax.Value
  1019.         $objInfo | Add-Member -MemberType NoteProperty -Name "AR" -Value $strARCar.Value
  1020.         $objInfo | Add-Member -MemberType NoteProperty -Name "Country" -Value $strCountry.Value
  1021.         $objInfo | Add-Member -MemberType NoteProperty -Name "Image" -Value $strImage
  1022.         $objInfo | Add-Member -MemberType NoteProperty -Name "Banner" -Value $Banner
  1023.     }
  1024.     catch
  1025.     {
  1026.         $errItemName = $_.Exception.ItemName
  1027.         Log-This -strLogLocation $strLogLocation -strErrorMessage "$errItemName - $_"
  1028.     }
  1029.  
  1030.     Return $objInfo
  1031. }
  1032.  
  1033. function Compare-Info
  1034. {
  1035. [cmdletbinding()]
  1036.     param(
  1037.  
  1038.     [parameter(Mandatory=$true,
  1039.             Position=0)]
  1040.     [validatenotnullorempty()]
  1041.     [string]$strLogLocation,
  1042.  
  1043.     [parameter(Mandatory=$true,
  1044.             Position=1)]
  1045.     [validatenotnullorempty()]
  1046.     $objInfo,
  1047.  
  1048.     [parameter(Mandatory=$true,
  1049.             Position=2)]
  1050.     [validatenotnullorempty()]
  1051.     [string]$strInfoLogLocation
  1052.  
  1053.     )
  1054.  
  1055.     $resetSig = $null
  1056.     $nl = [Environment]::NewLine
  1057.     try
  1058.     {
  1059.         if (!$(Test-Path $($env:appdata + "\Email-SignatureScript\data.csv")))
  1060.         {
  1061.             $objInfo | Export-Csv $($env:appdata + "\Email-SignatureScript\data.csv")
  1062.         }
  1063.         $objOldInfo = Import-Csv $($env:appdata + "\Email-SignatureScript\data.csv")
  1064.  
  1065.         $objOldInfo = Remove-NewLine -strLogLocation $strLogLocation -objOldInfo $objOldInfo
  1066.         If ($objOldInfo.DisplayName -ne $objInfo.DisplayName)
  1067.         {
  1068.             $resetSig = $true
  1069.             Log-This -strLogLocation $strLogLocation -strErrorMessage "Name Change"
  1070.         }
  1071.         If ($objOldInfo.Title -ne $objInfo.Title)
  1072.         {
  1073.             $resetSig = $true
  1074.             Log-This -strLogLocation $strLogLocation -strErrorMessage "Title Change"
  1075.         }
  1076.         If ($objOldInfo.Tel1 -ne $objInfo.Tel1)
  1077.         {
  1078.             $resetSig = $true
  1079.             Log-This -strLogLocation $strLogLocation -strErrorMessage "Tel1 Change"
  1080.         }
  1081.         If ($objOldInfo.Tel2 -ne $objInfo.Tel2)
  1082.         {
  1083.             $resetSig = $true
  1084.             Log-This -strLogLocation $strLogLocation -strErrorMessage "Tel2 Change"
  1085.         }
  1086.         If ($objOldInfo.Mob -ne $objInfo.Mob)
  1087.         {
  1088.             $resetSig = $true
  1089.             Log-This -strLogLocation $strLogLocation -strErrorMessage "Mob Change"
  1090.         }
  1091.         If ($objOldInfo.Mob2 -ne $objInfo.Mob2)
  1092.         {
  1093.             $resetSig = $true
  1094.             Log-This -strLogLocation $strLogLocation -strErrorMessage "Mob2 Change"
  1095.         }
  1096.         If ($objOldInfo.Company -ne $objInfo.Company)
  1097.         {
  1098.             $resetSig = $true
  1099.             Log-This -strLogLocation $strLogLocation -strErrorMessage "Company Change"
  1100.         }
  1101.         If ($objOldInfo.Department -ne $objInfo.Department)
  1102.         {
  1103.             $resetSig = $true
  1104.             Log-This -strLogLocation $strLogLocation -strErrorMessage "Department Change"
  1105.         }
  1106.         If ($objOldInfo.Fax -ne $objInfo.Fax)
  1107.         {
  1108.             $resetSig = $true
  1109.             Log-This -strLogLocation $strLogLocation -strErrorMessage "Fax Change"
  1110.         }
  1111.         If ($objOldInfo.AR -ne $objInfo.AR)
  1112.         {
  1113.             $resetSig = $true
  1114.             Log-This -strLogLocation $strLogLocation -strErrorMessage "AR Change"
  1115.         }
  1116.         If ($objOldInfo.Country -ne $objInfo.Country)
  1117.         {
  1118.             $resetSig = $true
  1119.             Log-This -strLogLocation $strLogLocation -strErrorMessage "Country Change"
  1120.         }
  1121.         If ($objOldInfo.Banner -ne $objInfo.Banner)
  1122.         {
  1123.             $resetSig = $true
  1124.             Log-This -strLogLocation $strLogLocation -strErrorMessage "Banner status change"
  1125.         }
  1126.  
  1127.         ##I convert to unix time since epoch ehre because compare dates wasn't working right
  1128.         if ($objOldInfo.Image -ne $null)
  1129.             {
  1130.             if ($objOldInfo.Image -like "*/*")
  1131.             {
  1132.                 $resetSig = $true
  1133.                 Log-This -strLogLocation $strLogLocation -strErrorMessage "Image? Change"
  1134.             }
  1135.             elseif ($objInfo.Image -gt $objOldInfo.Image)
  1136.             #If ($([Math]::Floor([decimal](Get-Date($dtOldImageLastWrite) -uformat "%s"))) -lt $([Math]::Floor([decimal](Get-Date($objInfo.Image) -uformat "%s"))))
  1137.             {
  1138.                 $resetSig = $true
  1139.                 Log-This -strLogLocation $strLogLocation -strErrorMessage "Image2? Change"
  1140.             }
  1141.         }
  1142.         else
  1143.         {
  1144.             $resetSig = $true
  1145.         }
  1146.     }
  1147.     catch
  1148.     {
  1149.         Log-This -strLogLocation $strLogLocation -strErrorMessage "$errItemName - $_"
  1150.         $resetSig = $false
  1151.     }
  1152.     Return $resetSig
  1153. }
  1154.  
  1155. function Reset-InfoLog
  1156. {
  1157. [cmdletbinding()]
  1158.     param(
  1159.  
  1160.     [parameter(Mandatory=$true,
  1161.             Position=0)]
  1162.     [validatenotnullorempty()]
  1163.     [string]$strLogLocation,
  1164.  
  1165.     [parameter(Mandatory=$true,
  1166.             Position=1)]
  1167.     [validatenotnullorempty()]
  1168.     $objInfo,
  1169.  
  1170.     [parameter(Mandatory=$true,
  1171.             Position=2)]
  1172.     [validatenotnullorempty()]
  1173.     [string]$strInfoLogLocation
  1174.  
  1175.     )
  1176.  
  1177.     try
  1178.     {
  1179.         if ($(test-path $strInfoLogLocation) -eq $true)
  1180.         {
  1181.             Rename-Item $strInfoLogLocation -NewName $($env:appdata + "\Email-SignatureScript\$(Get-Date -UFormat "%Y_%m_%d_%M").csv")
  1182.         }
  1183.         $objInfo | Export-Csv $($env:appdata + "\Email-SignatureScript\data.csv")
  1184.     }
  1185.     catch
  1186.     {
  1187.         Log-This -strLogLocation $strLogLocation -strErrorMessage "$errItemName - $_"
  1188.     }
  1189. }
  1190.  
  1191. Function Get-Banners
  1192. {
  1193.     [cmdletbinding()]
  1194.     param(
  1195.  
  1196.     [parameter(Mandatory=$true,
  1197.             Position=0)]
  1198.     [validatenotnullorempty()]
  1199.     [string]$strLogLocation,
  1200.  
  1201.     [parameter(Mandatory=$true,
  1202.             Position=1)]
  1203.     [validatenotnullorempty()]
  1204.     $objGroups
  1205.    
  1206.     )
  1207.     $objBanners = New-Object System.Object
  1208.     ##Define Banner group and info
  1209.     try
  1210.     {
  1211.         foreach ($group in $objGroups)
  1212.         {
  1213.             ## This needs to be the Distinguished name of the AD group
  1214.             if ($group -eq "CN=,OU=,OU=,DC=,=com" -and $(get-date) -lt $(Get-Date -Month 09 -Day 7 -Hour 17) -and $(get-date) -gt $(Get-Date -Month 08 -Day 01 -hour 0))
  1215.             {
  1216.                 $objBanners | Add-Member -MemberType NoteProperty -Name "Banners" -Value "Name" -Force
  1217.                 $objBanners | Add-Member -MemberType NoteProperty -Name "Start_Date" -Value $(Get-Date -Month 08 -Day 01) -Force
  1218.                 $objBanners | Add-Member -MemberType NoteProperty -Name "End_Date" -Value $(Get-Date -Month 09 -Day 7 -Hour 17) -Force
  1219.                 $objBanners | Add-Member -MemberType NoteProperty -Name "File_Location" -Value "$env:appdata\Microsoft\Stationery\banner1.jpg" -Force
  1220.             }
  1221.             if ($group -eq "CN=,OU=,OU=,DC=,=com" -and $(get-date) -lt $(Get-Date -Month 11 -Day 15 -Hour 17) -and $(get-date) -gt $(Get-Date -Month 10 -Day 01 -hour 0))
  1222.             {
  1223.                 $objBanners | Add-Member -MemberType NoteProperty -Name "Banners" -Value "Name2" -Force
  1224.                 $objBanners | Add-Member -MemberType NoteProperty -Name "Start_Date" -Value $(Get-Date -Month 10 -Day 01) -Force
  1225.                 $objBanners | Add-Member -MemberType NoteProperty -Name "End_Date" -Value $(Get-Date -Month 11 -Day 15 -Hour 17) -Force
  1226.                 $objBanners | Add-Member -MemberType NoteProperty -Name "File_Location" -Value "$env:appdata\Microsoft\Stationery\banner2.jpg" -Force
  1227.             }
  1228.         }
  1229.     }
  1230.     catch
  1231.     {
  1232.         $errItemName = $_.Exception.ItemName
  1233.         Log-This -strLogLocation $strLogLocation -strErrorMessage "$errItemName - $_"
  1234.     }
  1235.     Return $objBanners
  1236. }
  1237.  
  1238. function Remove-NewLine
  1239. {
  1240. [cmdletbinding()]
  1241.     param(
  1242.  
  1243.     [parameter(Mandatory=$true,
  1244.             Position=0)]
  1245.     [validatenotnullorempty()]
  1246.     [string]$strLogLocation,
  1247.  
  1248.     [parameter(Mandatory=$true,
  1249.             Position=1)]
  1250.     [validatenotnullorempty()]
  1251.     $objOldInfo
  1252.     )
  1253.  
  1254.     try
  1255.     {
  1256.         If ([string]::IsNullOrEmpty($objOldInfo.DisplayName))
  1257.         {
  1258.             $objOldInfo.DisplayName = $null
  1259.         }
  1260.         If ([string]::IsNullOrEmpty($objOldInfo.Title))
  1261.         {
  1262.             $objOldInfo.Title = $null
  1263.         }
  1264.         If ([string]::IsNullOrEmpty($objOldInfo.Tel1))
  1265.         {
  1266.             $objOldInfo.Tel1 = $null
  1267.         }
  1268.         If ([string]::IsNullOrEmpty($objOldInfo.Tel2))
  1269.         {
  1270.             $objOldInfo.Tel2 = $null
  1271.         }
  1272.         If ([string]::IsNullOrEmpty($objOldInfo.Mob))
  1273.         {
  1274.             $objOldInfo.Mob = $null
  1275.         }
  1276.         If ([string]::IsNullOrEmpty($objOldInfo.Mob2))
  1277.         {
  1278.             $objOldInfo.Mob2 = $null
  1279.         }
  1280.         If ([string]::IsNullOrEmpty($objOldInfo.Company))
  1281.         {
  1282.             $objOldInfo.Company = $null
  1283.         }
  1284.         If ([string]::IsNullOrEmpty($objOldInfo.Department))
  1285.         {
  1286.             $objOldInfo.Department = $null
  1287.         }
  1288.         If ([string]::IsNullOrEmpty($objOldInfo.Fax))
  1289.         {
  1290.             $objOldInfo.Fax = $null
  1291.         }
  1292.         If ([string]::IsNullOrEmpty($objOldInfo.AR))
  1293.         {
  1294.             $objOldInfo.AR = $null
  1295.         }
  1296.         If ([string]::IsNullOrEmpty($objOldInfo.Country))
  1297.         {
  1298.             $objOldInfo.Country = $null
  1299.         }
  1300.     }
  1301.     catch
  1302.     {
  1303.         Log-This -strLogLocation $strLogLocation -strErrorMessage "$errItemName - $_"
  1304.     }
  1305.     Return $objOldInfo
  1306. }
  1307.  
  1308. function Set-RegistryKeys
  1309. {
  1310.     [cmdletbinding()]
  1311.     param(
  1312.  
  1313.     [parameter(Mandatory=$true,
  1314.             Position=0)]
  1315.     [validatenotnullorempty()]
  1316.     [string]$strSignatureName
  1317.     )
  1318.  
  1319.     #Office 2010
  1320.     If (Test-Path HKCU:'\Software\Microsoft\Office\14.0')
  1321.     {
  1322.         if ($(Get-ItemProperty HKCU:'\Software\Microsoft\Office\14.0\Common\MailSettings' -Name 'NewSignature' -ErrorAction SilentlyContinue) -ne $strSignatureName)
  1323.         {
  1324.             Set-ItemProperty HKCU:'\Software\Microsoft\Office\14.0\Common\MailSettings' -Name 'NewSignature' -Value $strSignatureName -Force  | Out-Null
  1325.         }
  1326.         else
  1327.         {
  1328.             New-ItemProperty HKCU:'\Software\Microsoft\Office\14.0\Common\MailSettings' -Name 'NewSignature' -Value $strSignatureName -PropertyType 'String' -Force  | Out-Null
  1329.         }
  1330.         if ($(Get-ItemProperty HKCU:'\Software\Microsoft\Office\14.0\Common\MailSettings' -Name 'ReplySignature' -ErrorAction SilentlyContinue) -ne $strSignatureName)
  1331.         {
  1332.             Set-ItemProperty HKCU:'\Software\Microsoft\Office\14.0\Common\MailSettings' -Name 'ReplySignature' -Value $strSignatureName -Force  | Out-Null
  1333.         }
  1334.         else
  1335.         {
  1336.             New-ItemProperty HKCU:'\Software\Microsoft\Office\14.0\Common\MailSettings' -Name 'NewSignature' -Value $strSignatureName -PropertyType 'String' -Force  | Out-Null
  1337.         }
  1338.     }
  1339.  
  1340.     #Office 2013 signature
  1341.  
  1342.     If (Test-Path HKCU:'\Software\Microsoft\Office\15.0')
  1343.     {
  1344.         if ($(Get-ItemProperty HKCU:'\Software\Microsoft\Office\15.0\Common\MailSettings' -Name 'NewSignature' -ErrorAction SilentlyContinue) -ne $strSignatureName)
  1345.         {
  1346.             New-ItemProperty HKCU:'\Software\Microsoft\Office\15.0\Common\MailSettings' -Name 'NewSignature' -Value $strSignatureName -PropertyType 'String' -Force  | Out-Null
  1347.         }
  1348.         else
  1349.         {
  1350.             Set-ItemProperty HKCU:'\Software\Microsoft\Office\15.0\Common\MailSettings' -Name 'NewSignature' -Value $strSignatureName | Out-Null
  1351.         }
  1352.         if ($(Get-ItemProperty HKCU:'\Software\Microsoft\Office\15.0\Common\MailSettings' -Name 'ReplySignature' -ErrorAction SilentlyContinue) -ne $strSignatureName)
  1353.         {
  1354.             Set-ItemProperty HKCU:'\Software\Microsoft\Office\15.0\Common\MailSettings' -Name 'ReplySignature' -Value $strSignatureName -Force  | Out-Null
  1355.         }
  1356.         else
  1357.         {
  1358.             New-ItemProperty HKCU:'\Software\Microsoft\Office\15.0\Common\MailSettings' -Name 'ReplySignature' -Value $strSignatureName -PropertyType 'String' -Force  | Out-Null
  1359.         }
  1360.     }
  1361.  
  1362.     #Office 2016 signature
  1363.     If (Test-Path HKCU:'\Software\Microsoft\Office\16.0')
  1364.     {
  1365.         if ($(Get-ItemProperty HKCU:'\Software\Microsoft\Office\16.0\Common\MailSettings' -Name 'NewSignature' -ErrorAction SilentlyContinue) -ne $strSignatureName)
  1366.         {
  1367.             Set-ItemProperty HKCU:'\Software\Microsoft\Office\16.0\Common\MailSettings' -Name 'NewSignature' -Value $strSignatureName  -Force  | Out-Null
  1368.         }
  1369.         else
  1370.         {
  1371.             New-ItemProperty HKCU:'\Software\Microsoft\Office\16.0\Common\MailSettings' -Name 'NewSignature' -Value $strSignatureName -PropertyType 'String' -Force  | Out-Null
  1372.         }
  1373.         if ($(Get-ItemProperty HKCU:'\Software\Microsoft\Office\16.0\Common\MailSettings' -Name 'ReplySignature' -ErrorAction SilentlyContinue) -ne $strSignatureName)
  1374.         {
  1375.             Set-ItemProperty HKCU:'\Software\Microsoft\Office\16.0\Common\MailSettings' -Name 'ReplySignature' -Value $strSignatureName -Force  | Out-Null
  1376.         }
  1377.         else
  1378.         {
  1379.             New-ItemProperty HKCU:'\Software\Microsoft\Office\16.0\Common\MailSettings' -Name 'ReplySignature' -Value $strSignatureName -PropertyType 'String' -Force  | Out-Null
  1380.         }
  1381.     }
  1382. }
  1383.  
  1384. ##This will prevent the script from running if the c:\windows\NoAutoEmailSig.dat file exists or if it exists in the appdata folder
  1385. ##The idea for this is we can create the file if there are issues and use the old script to buy us time to troubleshoot.
  1386. if ($(Test-Path C:\Windows\NoAutoEmailSig.dat) -eq $true -or $(Test-Path "$env:APPDATA\Email-SignatureScript\NoAutoEmailSig.dat") -eq $true)
  1387. {
  1388.     ##Populate the string values below with your stuff
  1389.     if ($(test-path $("\\SERVERNAME\$env:COMPUTERNAME.txt")) -eq $false -and $(Test-Connection -Count 1 -ComputerName "SERVERNAME" -ErrorAction SilentlyContinue))
  1390.     {
  1391.         New-Item -Path $("\\SERVERNAME\$env:COMPUTERNAME.txt") -ItemType file | Out-Null
  1392.     }
  1393.     exit
  1394. }
  1395. else
  1396. {
  1397.     if ($(test-path $("\\SERVERNAME\$env:COMPUTERNAME.txt")) -eq $true -and $(Test-Connection -Count 1 -ComputerName "Servername" -ErrorAction SilentlyContinue))
  1398.     {
  1399.         gci "\\SERVERNAME\$env:COMPUTERNAME.txt" | Remove-Item
  1400.     }
  1401. }
  1402.  
  1403.  
  1404. ##I see no reason to run this on a server. I will do wmi fitlering on GPO also
  1405. if ($(Get-WmiObject -class Win32_OperatingSystem | select -expandProperty Caption | Out-String) -like "*Server*")
  1406. {
  1407.     exit
  1408. }
  1409.  
  1410. #Need connection to network for logging to work properly
  1411. if (!$(Test-Connection -Count 1 -ComputerName "SERVERNAME" -ErrorAction SilentlyContinue))
  1412. {
  1413.     exit
  1414. }
  1415.  
  1416. ##When adding picture Powershell 2.0 requires $objDocument.Range vs 5.0 which needs $objDocument.Range()
  1417. $intPSVersion = $PSVersionTable.PSVersion.Major
  1418. if ($PSVersionTable.PSVersion.Major -eq 2)
  1419. {
  1420.     $intPSVersion = 2
  1421. }
  1422.  
  1423. ##This will force the script to run in full if the file %appdata\Email-SignatureScript\ForceUpdate.dat exists
  1424. if ($(Test-Path "$env:APPDATA\Email-SignatureScript\ForceUpdate.dat") -eq $true)
  1425. {
  1426.     Remove-Item "$env:APPDATA\Email-SignatureScript\ForceUpdate.dat" -force
  1427.     Remove-Item "$env:APPDATA\Microsoft\Signatures" -Recurse -force
  1428. }
  1429.  
  1430. ##New line character for country info
  1431. $nl = [System.Environment]::NewLine
  1432.  
  1433. Create-Log -strComputerName $env:COMPUTERNAME
  1434.  
  1435. ##Set Log Path Variable
  1436. $strLogLocation = Get-LogLocation -strComputerName $env:COMPUTERNAME
  1437.  
  1438. Log-This -strLogLocation $strLogLocation -strErrorMessage "Script Trigggered"
  1439.  
  1440. #Environment variables
  1441. $strSignatureName = "Reddit Signature v1"
  1442. $strAppData=(Get-Item env:appdata).value
  1443. $strSigPath = '\Microsoft\Signatures'
  1444. $strLocalSignaturePath = $strAppData+$strSigPath
  1445.  
  1446. ##Create Sig Folder
  1447. If (!(Test-Path -path $strLocalSignaturePath))
  1448. {
  1449.     New-Item $strLocalSignaturePath -Type Directory | Out-Null
  1450. }
  1451.  
  1452.  
  1453. ##Get AD Info
  1454. $strUserName = $env:USERNAME
  1455. $strFilter = "(&(objectCategory=User)(samAccountName=$strUserName))"
  1456. $objSearcher = New-Object System.DirectoryServices.DirectorySearcher
  1457. $objSearcher.Filter = $strFilter
  1458. $objADUserPath = $objSearcher.FindOne()
  1459. if ($objADUserPath -ne $null)
  1460. {
  1461.     $objADUser = $objADUserPath.GetDirectoryEntry()
  1462.     $strADDisplayName = $objADUser.DisplayName
  1463.     $strADTitle = $objADUser.title
  1464.     $strADTelePhoneNumber = $objADUser.TelephoneNumber
  1465.     $strADTelePhoneNumber2 = $objADUser.extensionAttribute1
  1466.     $strADMobile = $objADUser.mobile
  1467.     $strADMobile2 = $objADUser.extensionAttribute2
  1468.     $strADCompany = $objADUser.company
  1469.     $strDepartment = $objADUser.Department
  1470.     $strFax = $objADUser.facsimileTelephoneNumber
  1471.     $strARCar = $objADUser.extensionAttribute10
  1472.     $strCountry = $objADUser.co
  1473.     $objMemberOf = $objADUser.memberOf
  1474. }
  1475.  
  1476. #Get banner info and determine if one is needed
  1477. $objBanner = Get-Banners -strLogLocation $strLogLocation -objGroups $objMemberOf
  1478. if ($objBanner.banners -ne $null -and $(get-date) -lt $objBanner.End_Date -and $(get-date) -gt $objBanner.Start_Date)
  1479. {
  1480.     $bolBanner = $true
  1481. }
  1482. else
  1483. {
  1484.     $bolBanner = $false
  1485. }
  1486.  
  1487. ##Get Company specific info
  1488. $objCompanyInfo = Set-CompanyInfo -strLogLocation $strLogLocation -strADCompany $strADCompany
  1489. $strSignatureName = $objCompanyInfo.Signame
  1490.  
  1491. ##FOR TESTING ONLY
  1492. ##$strCountry = "United Kingdom"
  1493. ##$strARCar = "AR"
  1494.  
  1495. ##Timestamp and unix timestamp for the logo (This is killing me...)
  1496. $dtLocalLogoTimeStamp = $(get-date $([datetime]$(gci $objCompanyInfo.Picture | select -ExpandProperty LastWriteTime)))
  1497. $strTimeSinceEpoch = $(New-TimeSpan -Start ('01/01/1970') -end $dtLocalLogoTimeStamp).Days
  1498.  
  1499. ##Compare new data and previous data to determine if script needs to be run
  1500. $strInfoLogLocation = $($($env:appdata + "\Email-SignatureScript\data.csv"))
  1501. $objInfo = Create-InfoObject -strLogLocation $strLogLocation -strADDisplayName $strADDisplayName -strADTitle $strADTitle -strADTelePhoneNumber $strADTelePhoneNumber -strADTelePhoneNumber2 $strADTelePhoneNumber2 -strADMobile $strADMobile -strADMobile2 $strADMobile2 -strADCompany $strADCompany -strDepartment $strDepartment -strFax $strFax -strARCar $strARCar -strCountry $strCountry -strImage $strTimeSinceEpoch -strInfoLogLocation $strInfoLogLocation -Banner $bolBanner
  1502. $strSigReset = Compare-Info -strLogLocation $strLogLocation -objInfo $objInfo -strInfoLogLocation $strInfoLogLocation
  1503. if ($strSigReset)
  1504. {
  1505.     Reset-InfoLog -strLogLocation $strLogLocation -objInfo $objInfo -strInfoLogLocation $strInfoLogLocation
  1506. }
  1507. elseif ( $(gci -path $($strLocalSignaturePath + "\")) -eq $null)
  1508. {
  1509.     Reset-InfoLog -strLogLocation $strLogLocation -objInfo $objInfo -strInfoLogLocation $strInfoLogLocation
  1510. }
  1511. else
  1512. {
  1513.     Log-This -strLogLocation $strLogLocation -strErrorMessage "Completed - No need to run"
  1514.     Set-RegistryKeys -strSignatureName $strSignatureName | Out-Null
  1515.     break
  1516. }
  1517.  
  1518. ##Get Country specific info
  1519. $objCountryInfo = Set-CountryInfo -strLogLocation $strLogLocation -strCountry $strCountry -strADCompany $strADCompany
  1520.  
  1521. ##Create com object and set spacing
  1522. $arrWordBefore = Get-Process -Name "WINWORD" -ErrorAction SilentlyContinue
  1523. $comMSWord = New-Object -ComObject word.application
  1524. $arrWordAfter = Get-Process -Name "WINWORD"
  1525. if ($arrWordBefore -ne $null)
  1526. {
  1527.     $objWord = Compare-Object $arrWordBefore $arrWordAfter | select -ExpandProperty InputObject
  1528. }
  1529. else
  1530. {
  1531.     $objWord = $arrWordAfter
  1532. }
  1533. $comMSWord.Visible = $false
  1534. $objDocument = $comMSWord.Documents.Add()
  1535. $objDocument.Paragraphs.SpaceAfter = 0
  1536. $objDocument.Paragraphs.SpaceAfter = 0
  1537. $objSelection = $comMSWord.Selection
  1538.  
  1539. ##Add Name to document
  1540. $objNameStyle = Create-StyleObject -strLogLocation $strLogLocation -intFontSize 11 -intBold 1 -intItalic $null -strColor $null -strName "Calibri"
  1541. $objSelection = Add-Name -strLogLocation $strLogLocation -objSelection $objSelection -strADDisplayName $strADDisplayName -objNameStyle $objNameStyle
  1542. Remove-Variable objNameStyle
  1543.  
  1544. ##Add Title to Document
  1545. $objTitleStyle = Create-StyleObject -strLogLocation $strLogLocation -intFontSize 11 -intBold 0 -intItalic $null -strColor $null -strName "Calibri"
  1546. $objSelection = Add-Title -strLogLocation $strLogLocation -objSelection $objSelection -strADTitle $strADTitle -objTitleStyle $objTitleStyle
  1547. Remove-Variable objTitleStyle
  1548.  
  1549. ##Add Telephone if it exists
  1550. if ( $strADTelePhoneNumber -ne $null)
  1551. {
  1552.     $objtelStyle = Create-StyleObject -strLogLocation $strLogLocation -intFontSize 11 -intBold 0 -intItalic $null -strColor $null -strName "Calibri"
  1553.     $objSelection = Add-Tel -strLogLocation $strLogLocation -objSelection $objSelection -strADTelePhoneNumber $strADTelePhoneNumber -objTelStyle $objtelStyle
  1554.     Remove-Variable objtelStyle
  1555. }
  1556.  
  1557. ##Add Telephone2 if it exists
  1558. if ( $strADTelePhoneNumber2 -ne $null)
  1559. {
  1560.     $objtelStyle = Create-StyleObject -strLogLocation $strLogLocation -intFontSize 11 -intBold 0 -intItalic $null -strColor $null -strName "Calibri"
  1561.     $objSelection = Add-Tel -strLogLocation $strLogLocation -objSelection $objSelection -strADTelePhoneNumber $strADTelePhoneNumber2 -objTelStyle $objtelStyle
  1562.     Remove-Variable objtelStyle
  1563. }
  1564.  
  1565. ##Add Mobile if it exists
  1566. if ( $strADMobile -ne $null)
  1567. {
  1568.     $objMobileStyle = Create-StyleObject -strLogLocation $strLogLocation -intFontSize 11 -intBold 0 -intItalic $null -strColor $null -strName "Calibri"
  1569.     $objSelection = Add-Mobile -strLogLocation $strLogLocation -objSelection $objSelection -strADMobile $strADMobile -objMobileStyle $objMobileStyle
  1570.     Remove-Variable objMobileStyle
  1571. }
  1572.  
  1573. ##Add Mobile2 if it exists
  1574. if ( $strADMobile2 -ne $null)
  1575. {
  1576.     $objMobileStyle = Create-StyleObject -strLogLocation $strLogLocation -intFontSize 11 -intBold 0 -intItalic $null -strColor $null -strName "Calibri"
  1577.     $objSelection = Add-Mobile2 -strLogLocation $strLogLocation -objSelection $objSelection -strADMobile $strADMobile2 -objMobileStyle $objMobileStyle
  1578.     Remove-Variable objMobileStyle
  1579. }
  1580.  
  1581. ##Add Fax if it exists
  1582. if ( $strFax -ne $null)
  1583. {
  1584.     $objFaxStyle = Create-StyleObject -strLogLocation $strLogLocation -intFontSize 11 -intBold 0 -intItalic $null -strColor $null -strName "Calibri"
  1585.     $objSelection = Add-Fax -strLogLocation $strLogLocation -objSelection $objSelection -strADFax $strFax -objFaxStyle $objFaxStyle
  1586.     Remove-Variable objFaxStyle
  1587. }
  1588.  
  1589. ##Add Company specific data
  1590. $objSelection = Add-CompanySpecific -strLogLocation $strLogLocation -objSelection $objSelection -objDocument $objDocument -objCompanyInfo $objCompanyInfo -intPSVersion $intPSVersion -objBanner $objBanner -bolBanner $bolBanner
  1591.  
  1592. ##Add AR info if needed
  1593. if ( $strARCar -ne $null)
  1594. {
  1595.     $objARStyle = Create-StyleObject -strLogLocation $strLogLocation -intFontSize 8 -intBold 0 -intItalic $null -strColor $null -strName "Calibri"
  1596.     $objSelection = Add-ARInfo -strLogLocation $strLogLocation -objSelection $objSelection[2] -objArStyle $objARStyle
  1597.     Remove-Variable objARStyle
  1598. }
  1599.  
  1600. ##Add country specific info if needed
  1601. if ( $objCountryInfo -ne $null)
  1602. {
  1603.     if ($strARCar -ne $null)
  1604.     {
  1605.         $objCountryStyle = Create-StyleObject -strLogLocation $strLogLocation -intFontSize 8 -intBold 0 -intItalic $null -strColor $null -strName "Calibri"
  1606.         $objSelection = Add-CountrySpecific -strLogLocation $strLogLocation -objSelection $objSelection -objCountryStyle $objCountryStyle -objCountryInfo $objCountryInfo
  1607.         Remove-Variable objCountryStyle
  1608.     }
  1609.     else
  1610.     {
  1611.         $objCountryStyle = Create-StyleObject -strLogLocation $strLogLocation -intFontSize 8 -intBold 0 -intItalic $null -strColor $null -strName "Calibri"
  1612.         $objSelection = Add-CountrySpecific -strLogLocation $strLogLocation -objSelection $objSelection[2] -objCountryStyle $objCountryStyle -objCountryInfo $objCountryInfo
  1613.         Remove-Variable objCountryStyle
  1614.     }
  1615. }
  1616.  
  1617. if ($strSigReset)
  1618. {
  1619.     $objSignatureFiles = gci $strLocalSignaturePath | select -ExpandProperty FullName
  1620.     foreach ($strFile in $objSignatureFiles)
  1621.     {
  1622.         Remove-Item $strFile -force -Recurse
  1623.     }
  1624. }
  1625.  
  1626.  
  1627.  
  1628. #Save HTML
  1629. try
  1630. {
  1631.     $refSaveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatHTML");
  1632.     $refPath = "$strLocalSignaturePath\$strSignatureName.htm"
  1633.     $comMSWord.ActiveDocument.SaveAs([ref][system.object]$refPath, [ref]$refSaveFormat)
  1634. }
  1635. catch
  1636. {
  1637.     Log-This -strLogLocation $strLogLocation -strErrorMessage $_
  1638.     Log-This -strLogLocation $strLogLocation -strErrorMessage $refPath
  1639.     Log-This -strLogLocation $strLogLocation -strErrorMessage $refSaveFormat
  1640. }
  1641.      
  1642. #Save RTF
  1643. try
  1644. {
  1645.     $refSaveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatRTF");
  1646.     $refPath = "$strLocalSignaturePath\$strSignatureName.rtf"
  1647.     $comMSWord.ActiveDocument.SaveAs([ref][system.object]$refPath, [ref]$refSaveFormat)
  1648. }
  1649. catch
  1650. {
  1651.     Log-This -strLogLocation $strLogLocation -strErrorMessage $_
  1652.     Log-This -strLogLocation $strLogLocation -strErrorMessage $refPath
  1653.     Log-This -strLogLocation $strLogLocation -strErrorMessage $refSaveFormat
  1654. }
  1655.      
  1656. #Save TXT
  1657. try
  1658. {
  1659.     $refSaveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatText");
  1660.     $refPath = "$strLocalSignaturePath\$strSignatureName.txt"
  1661.     $comMSWord.ActiveDocument.SaveAs([ref][system.object]$refPath, [ref]$refSaveFormat)
  1662.     $comMSWord.ActiveDocument.Close()
  1663.     $comMSWord.Quit()
  1664.     [System.Runtime.Interopservices.Marshal]::ReleaseComObject($comMSWord)
  1665. }
  1666. catch
  1667. {
  1668.     Log-This -strLogLocation $strLogLocation -strErrorMessage $_
  1669.     Log-This -strLogLocation $strLogLocation -strErrorMessage $refPath
  1670.     Log-This -strLogLocation $strLogLocation -strErrorMessage $refSaveFormat
  1671. }
  1672.  
  1673. Start-Sleep -Seconds 5
  1674.  
  1675. Set-RegistryKeys -strSignatureName $strSignatureName | Out-Null
  1676.  
  1677. Log-This -strLogLocation $strLogLocation -strErrorMessage "Completed - $(get-date)"
  1678. if ($(Get-Process -Id $objWord.ID -ErrorAction SilentlyContinue) -ne $null)
  1679. {
  1680.     Stop-Process $objWord -Force
  1681. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement