Какой параметр Powershell отвечает за разметку страницы в Word'е?
#39849609
Ссылка:
Ссылка на сообщение:
Ссылка с названием темы:
|
|
|
Камрады, есть скрипт на powershell, который выставляет подпись в Outlook автоматически, но в месте с этим он меняет разметку в ворде на "Веб-документ". Из-за чего пользователю приходится каждый раз переключать ее обратно на вкладке "Вид".
Сам скрипт:
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119. 120. 121. 122. 123. 124. 125. 126. 127. 128. 129. 130. 131. 132. 133. 134. 135. 136. 137. 138. 139. 140. 141. 142. 143. 144. 145. 146. 147. 148. 149. 150. 151. 152. 153. 154. 155. 156. 157. 158. 159. 160. 161. 162. 163. 164. 165. 166. 167. 168. 169. 170. 171. 172. 173. 174. 175. 176. 177. 178. 179. 180. 181. 182. 183. 184. 185. 186. 187. 188. 189. 190. 191. 192. 193. 194. 195. 196. 197. 198. 199. 200. 201. 202. 203. 204. 205. 206. 207. 208. 209. 210. 211. 212. 213. 214. 215. 216. 217. 218. 219. 220. 221. 222. 223. 224. 225. 226. 227. 228. 229. 230. 231. 232. 233. 234. 235. 236. 237. 238.
#Custom variables
$CompanyName = ‘company'
$SigSource = "\\company\SysVol\company\Policies\{0CD7D3A9-1B70-4503-8746-89BC60B5F3F4}\User\Scripts\Logon\$CompanyName"
$ForceSignatureNew = '1' #When the signature are forced the signature are enforced as default signature for new messages the next time the script runs. 0 = no force, 1 = force
$ForceSignatureReplyForward = '1' #When the signature are forced the signature are enforced as default signature for reply/forward messages the next time the script runs. 0 = no force, 1 = force
#Environment variables
$AppData=(Get-Item env:appdata).value
$SigPath = ‘\Microsoft\Signatures'
$LocalSignaturePath = $AppData+$SigPath
$LocalSignatureFile = $LocalSignaturePath+'\'+$CompanyName+'.files'
$RemoteSignaturePathFull = $SigSource+'\'+$CompanyName+'.docx'
#Get Active Directory information for current user
$UserName = $env:username
$Filter = "(&(objectCategory=User)(samAccountName=$UserName))"
$Searcher = New-Object System.DirectoryServices.DirectorySearcher
$Searcher.Filter = $Filter
$ADUserPath = $Searcher.FindOne()
$ADUser = $ADUserPath.GetDirectoryEntry()
$ADDisplayName = $ADUser.DisplayName
$ADipPhone = $ADUser.ipPhone
$ADTitle = $ADUser.title
$ADTelePhoneNumber = $ADUser.TelephoneNumber
$ADhomePhone = $ADUser.homePhone
$ADCompany = $ADUser.Company
$ADTitleEng = $ADUser.description
$ADinfo = $ADUser.info
#Setting registry information for the current user
$CompanyRegPath = "HKCU:\Software\"+$CompanyName
if (Test-Path $CompanyRegPath)
{}
else
{New-Item -path "HKCU:\Software" -name $CompanyName}
if (Test-Path $CompanyRegPath'\Outlook Signature Settings')
{}
else
{New-Item -path $CompanyRegPath -name "Outlook Signature Settings"}
$SigVersion = (gci $RemoteSignaturePathFull).LastWriteTime #When was the last time the signature was written
$ForcedSignatureNew = (Get-ItemProperty $CompanyRegPath'\Outlook Signature Settings').ForcedSignatureNew
$ForcedSignatureReplyForward = (Get-ItemProperty $CompanyRegPath'\Outlook Signature Settings').ForcedSignatureReplyForward
$SignatureVersion = (Get-ItemProperty $CompanyRegPath'\Outlook Signature Settings').SignatureVersion
Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name SignatureSourceFiles -Value $SigSource
#присваиваем переменные взяв значения из реестра
$TelephoneNumberREG = (Get-ItemProperty $CompanyRegPath'\Outlook Signature Settings').TelephoneNumber
$DisplayNameREG = (Get-ItemProperty $CompanyRegPath'\Outlook Signature Settings').DisplayName
$ipPhoneREG = (Get-ItemProperty $CompanyRegPath'\Outlook Signature Settings').ipPhone
$ADTitleREG = (Get-ItemProperty $CompanyRegPath'\Outlook Signature Settings').ADTitle
$ADhomePhoneREG = (Get-ItemProperty $CompanyRegPath'\Outlook Signature Settings').homePhone
$ADCompanyREG = (Get-ItemProperty $CompanyRegPath'\Outlook Signature Settings').Company
$ADTitleEngREG = (Get-ItemProperty $CompanyRegPath'\Outlook Signature Settings').description
$ADinfoREG = (Get-ItemProperty $CompanyRegPath'\Outlook Signature Settings').info
$SignatureSourceFiles = (Get-ItemProperty $CompanyRegPath'\Outlook Signature Settings').SignatureSourceFiles
#Forcing signature for new messages if enabled
if ($ForcedSignatureNew -eq '1')
{
#Set company signature as default for New messages
$MSWord = New-Object -com word.application
$EmailOptions = $MSWord.EmailOptions
$EmailSignature = $EmailOptions.EmailSignature
$EmailSignatureEntries = $EmailSignature.EmailSignatureEntries
$EmailSignature.NewMessageSignature=$CompanyName
$MSWord.Quit()
}
#Forcing signature for reply/forward messages if enabled
if ($ForcedSignatureReplyForward -eq '1')
{
#Set company signature as default for Reply/Forward messages
$MSWord = New-Object -com word.application
$EmailOptions = $MSWord.EmailOptions
$EmailSignature = $EmailOptions.EmailSignature
$EmailSignatureEntries = $EmailSignature.EmailSignatureEntries
$EmailSignature.ReplyMessageSignature=$CompanyName
$MSWord.Quit()
}
#Copying signature sourcefiles and creating signature if signature-version are different from local version
$FileExists = Test-Path "$LocalSignatureFile"
if ($SignatureVersion -eq $SigVersion -And $TelephoneNumberREG -eq $ADTelePhoneNumber -And $DisplayNameREG -eq $ADDisplayName -And $ipPhoneREG -eq $ADipPhone -And $ADTitleREG -eq $ADTitle -And $ADhomePhoneREG -eq $ADhomePhone -And $ADCompanyREG -eq $ADCompany -And $ADTitleEngREG -eq $ADTitleEng -And $ADinfoREG -eq $ADinfo -and $FileExists -eq $true) {}
else
{
#Copy signature templates from domain to local Signature-folder
Copy-Item "$SignatureSourceFiles\*" $LocalSignaturePath -Recurse -Force
$ReplaceAll = 2
$FindContinue = 1
$MatchCase = $False
$MatchWholeWord = $True
$MatchWildcards = $False
$MatchSoundsLike = $False
$MatchAllWordForms = $False
$Forward = $True
$Wrap = $FindContinue
$Format = $False
#Insert variables from Active Directory to rtf signature-file
$MSWord = New-Object -com word.application
$fullPath = $LocalSignaturePath+'\'+$CompanyName+'.docx'
$MSWord.Documents.Open($fullPath)
$FindText = "TelephoneNumber"
$ReplaceText = $ADTelephoneNumber.ToString()
$MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord, $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap, $Format, $ReplaceText, $ReplaceAll )
$FindText = "DisplayName"
$ReplaceText = $ADDisplayName.ToString()
$MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord, $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap, $Format, $ReplaceText, $ReplaceAll )
$FindText = "Title"
$ReplaceText = $ADTitle.ToString()
$MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord, $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap, $Format, $ReplaceText, $ReplaceAll )
$FindText = "ipPhone"
$ReplaceText = $ADipPhone.ToString()
$MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord, $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap, $Format, $ReplaceText, $ReplaceAll )
$FindText = "info"
$ReplaceText = $ADinfo.ToString()
$MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord, $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap, $Format, $ReplaceText, $ReplaceAll )
$FindText = "homePhone"
$ReplaceText = $ADhomePhone.ToString()
$MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord, $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap, $Format, $ReplaceText, $ReplaceAll )
$FindText = "description"
$ReplaceText = $ADTitleEng.ToString()
$MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord, $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap, $Format, $ReplaceText, $ReplaceAll )
$FindText = "Company"
$ReplaceText = $ADCompany.ToString()
$MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord, $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap, $Format, $ReplaceText, $ReplaceAll )
$MSWord.ActiveDocument.Save()
$saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatHTML");
[ref]$BrowserLevel = "microsoft.office.interop.word.WdBrowserLevel" -as [type]
$MSWord.ActiveDocument.WebOptions.OrganizeInFolder = $true
$MSWord.ActiveDocument.WebOptions.UseLongFileNames = $true
$MSWord.ActiveDocument.WebOptions.BrowserLevel = $BrowserLevel::wdBrowserLevelMicrosoftInternetExplorer6
$path = $LocalSignaturePath+'\'+$CompanyName+".htm"
$MSWord.ActiveDocument.saveas([ref]$path, [ref]$saveFormat)
$MSWord.ActiveDocument.DefaultWebOptions.OrganizeInFolder = $False
#$MSWord.ActiveDocument.WebOptions.OrganizeInFolder = $False
$saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], “wdFormatText”);
$path = $LocalSignaturePath+'\'+$CompanyName+”.rtf”
$MSWord.ActiveDocument.SaveAs([ref] $path, [ref]$saveFormat)
#$saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatRTF");
#$path = $LocalSignaturePath+'\'+$CompanyName+".rtf"
#$MSWord.ActiveDocument.SaveAs([ref] $path, [ref]$saveFormat)
$path = $LocalSignaturePath+'\'+$CompanyName+".txt"
$MSWord.ActiveDocument.SaveAs([ref] $path, [ref]$SaveFormat)
$MSWord.ActiveDocument.Close()
$MSWord.Quit()
}
#Stamp registry-values for Outlook Signature Settings if they doesn`t match the initial script variables. Note that these will apply after the second script run when changes are made in the "Custom variables"-section.
if ($ForcedSignatureNew -eq $ForceSignatureNew){}
else
{Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name ForcedSignatureNew -Value $ForceSignatureNew}
if ($ForcedSignatureReplyForward -eq $ForceSignatureReplyForward){}
else
{Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name ForcedSignatureReplyForward -Value $ForceSignatureReplyForward}
if ($SignatureVersion -eq $SigVersion){}
else
{Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name SignatureVersion -Value $SigVersion}
#проверить актуальность тел. номера
if ($TelephoneNumberREG -eq $ADTelePhoneNumber){}
else
{Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name TelephoneNumber -Value $ADTelePhoneNumber}
if ($TelephoneNumberREG -eq $ADTelePhoneNumber){}
else
{Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name TelephoneNumber -Value $ADTelePhoneNumber}
#проверить актуальность ФИО
if ($DisplayNameREG -eq $ADDisplayName){}
else
{Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name DisplayName -Value $ADDisplayName}
if ($DisplayNameREG -eq $ADDisplayName){}
else
{Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name DisplayName -Value $ADDisplayName}
#проверить актуальность должности
if ($ADTitleREG -eq $ADTitle){}
else
{Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name ADTitle -Value $ADTitle}
if ($ADTitleREG -eq $ADTitle){}
else
{Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name ADTitle -Value $ADTitle}
#проверить актуальность
if ($ADinfoREG -eq $ADinfo){}
else
{Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name ADTitle -Value $ADinfo}
if ($ADinfoREG -eq $ADinfo){}
else
{Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name ADTitle -Value $ADinfo}
#проверить актуальность
if ($ADhomePhoneREG -eq $ADhomePhone){}
else
{Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name ADTitle -Value $ADhomePhone}
if ($ADhomePhoneREG -eq $ADhomePhone){}
else
{Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name ADTitle -Value $ADhomePhone}
#проверить актуальность
if ($ADCompanyREG -eq $ADCompany){}
else
{Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name ADTitle -Value $ADCompany}
if ($ADCompanyREG -eq $ADCompany){}
else
{Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name ADTitle -Value $ADCompany}
#проверить актуальность
if ($ADTitleEngREG -eq $ADTitleEng){}
else
{Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name ADTitle -Value $ADTitleEng}
if ($ADTitleEngREG -eq $ADTitleEng){}
else
{Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name ADTitle -Value $ADTitleEng}
Разметка меняется в момент сохранения документов в формате html, а именно на строке
1. 2.
$MSWord.ActiveDocument.WebOptions.OrganizeInFolder = $true
$MSWord.ActiveDocument.WebOptions.UseLongFileNames = $true
Самый очевидный вариант, заменить значения на False и поставить перед закрытием файла и самого приложения word не сработал.
Подскажите какой параметр может отвечать за данный функционал?
|
|