Question regarding syntax with powershell

I am trying to use a powershell app I found online to automatically sent an otc file via powershell. I am clueless as to syntax. Getting syntax error with this piece$olApp = New-Object -ComObject Outlook.Application
$objMsg = $olApp.CreateItemFromTemplate ($Path"c:\scripts\test.oft")
This is the error I get.

PS C:\scripts> C:\Scripts\Send-OutlookMailFromTemplate.ps1
At C:\Scripts\Send-OutlookMailFromTemplate.ps1:43 char:42

  • $objMsg = $olApp.CreateItemFromTemplate ($Path"c:\scripts\test.of ...
    
  •                                         ~
    

Unexpected token ‘(’ in expression or statement.
At C:\Scripts\Send-OutlookMailFromTemplate.ps1:43 char:48

  • … $objMsg = $olApp.CreateItemFromTemplate ($Path"c:\scripts\test.oft")
  •                                                ~~~~~~~~~~~~~~~~~~~~~
    

Unexpected token ‘“c:\scripts\test.oft”’ in expression or statement.
At C:\Scripts\Send-OutlookMailFromTemplate.ps1:43 char:48

  • $objMsg = $olApp.CreateItemFromTemplate ($Path"c:\scripts\test.of ...
    
  •                                               ~
    

Missing closing ‘)’ in expression.
At C:\Scripts\Send-OutlookMailFromTemplate.ps1:2 char:1

  • {
  • ~
    Missing closing ‘}’ in statement block or type definition.
    At C:\Scripts\Send-OutlookMailFromTemplate.ps1:43 char:69
  • … $objMsg = $olApp.CreateItemFromTemplate ($Path"c:\scripts\test.oft")
  •                                                                     ~
    

Unexpected token ‘)’ in expression or statement.
At C:\Scripts\Send-OutlookMailFromTemplate.ps1:60 char:1

  • }
  • ~
    Unexpected token ‘}’ in expression or statement.
    • CategoryInfo : ParserError: (:slight_smile: , ParentContainsErrorRecordException
    • FullyQualifiedErrorId : UnexpectedToken

Here is the link to the program. My file resides in c:\scripts\test.oft

Any help would be greatly appreciated. I am frankly clueless. Thanks

My guess would be you’ve copied and pasted some weird characters or whitespace. Try using visual studio code and it should highlight the syntax errors. Start at the first. Many times one syntax error can cause many others after it.

1 Like

kevin,
Welcome to the forum. :wave:t4:

If you find code online and you have issues with that you should contact the author first. He/she probably knows the code best.

next …
When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in PowerShell.org <---- Click :point_up_2:t4: :wink:

Regardless of that …

Doug is right. You obviously have additional spaces right before the parenmthesis. If you’d used VSCode it would have pointed this out.

Thanks everyone I downloaded visual studio and unzipped file rather than copy and paste as well. Ran without errors.

… it is not Visual Studio - it is Visual Studio Code !!! :point_up_2:t4:

lol. It is that’s what I meant. Been long day.

1 Like