2016-03-23 26 views
1

我有這個腳本創建一個Outlook簽名並查找日期(DisplayName,Telephone和Title)的Active Directory。展望2016年簽名和活動目錄

我有這行代碼將.docx文件複製到appdata並將其保存在html,rtf和txt中。

#Save new message signature 
Write-Output "Saving signatures" 
#Save HTML 
$saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatHTML"); 
$path = $LocalSignaturePath+'\'+$SignatureName+".htm" 
$MSWord.ActiveDocument.saveas([ref]$path, [ref]$saveFormat) 

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

#Save TXT  
$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() 

它正常工作的Outlook 2013年但是,當我跑了用於Outlook 2016年,我收到以下錯誤

Unable to find type [Microsoft.Office.Interop.Word.WdSaveFormat]. 
At C:\Users\rob\Downloads\set_outlook_signature\set_outlook_signature.ps1:142 char:1 
+ $saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveForm ... 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : InvalidOperation: (Microsoft.Offic...rd.WdSaveFormat:TypeName) [], RuntimeException 
    + FullyQualifiedErrorId : TypeNotFound 

[ref] cannot be applied to a variable that does not exist. 
At C:\Users\rob\Downloads\set_outlook_signature\set_outlook_signature.ps1:144 char:1 
+ $MSWord.ActiveDocument.saveas([ref]$path, [ref]$saveFormat) 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : InvalidOperation: (saveFormat:VariablePath) [], RuntimeException 
    + FullyQualifiedErrorId : NonExistingVariableReference 

Unable to find type [Microsoft.Office.Interop.Word.WdSaveFormat]. 
At C:\Users\rob\Downloads\set_outlook_signature\set_outlook_signature.ps1:147 char:1 
+ $saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveForm ... 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : InvalidOperation: (Microsoft.Offic...rd.WdSaveFormat:TypeName) [], RuntimeException 
    + FullyQualifiedErrorId : TypeNotFound 

[ref] cannot be applied to a variable that does not exist. 
At C:\Users\rob\Downloads\set_outlook_signature\set_outlook_signature.ps1:149 char:1 
+ $MSWord.ActiveDocument.SaveAs([ref] $path, [ref]$saveFormat) 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : InvalidOperation: (saveFormat:VariablePath) [], RuntimeException 
    + FullyQualifiedErrorId : NonExistingVariableReference 

Unable to find type [Microsoft.Office.Interop.Word.WdSaveFormat]. 
At C:\Users\rob\Downloads\set_outlook_signature\set_outlook_signature.ps1:152 char:1 
+ $saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveForm ... 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : InvalidOperation: (Microsoft.Offic...rd.WdSaveFormat:TypeName) [], RuntimeException 
    + FullyQualifiedErrorId : TypeNotFound 

[ref] cannot be applied to a variable that does not exist. 
At C:\Users\rob\Downloads\set_outlook_signature\set_outlook_signature.ps1:154 char:1 
+ $MSWord.ActiveDocument.SaveAs([ref] $path, [ref]$SaveFormat) 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : InvalidOperation: (SaveFormat:VariablePath) [], RuntimeException 
    + FullyQualifiedErrorId : NonExistingVariableReference 

是否有用於Outlook 2016思考不同的格式化?

謝謝!

+0

你是做什麼的OSX或者MacOS @rob員工做 – OnkelK

回答

0

如果您安裝了32位Office,請嘗試在32位中運行腳本PowerShell

我做了一個.bat文件執行下面+腳本

%SystemRoot%\syswow64\WindowsPowerShell\v1.0\powershell.exe c:\myscript.ps1