-1

Does this seem to be correct? I am getting errors on trying to convert .vss to .vssx.

     >> $directoryToUpdate='C:\office\Stencils\*'
     >> $visio= New-Object -comVisio.Application
     >> foreach($vssFile in (get-childitem "$directoryToUpdate\*.vss" -Recurse")){
     >>    write-host "Working on $vssfile"
     >>    $doc=$visio.Documents.Open($vssFile.FullName)
     >>    $vssxFileName=[io.path]::ChangeExtension($vssFile,'.vssx')
     >>    $doc.SaveAs($VSSXFileName)
     >>    $doc.close();
     >> }

The output error messages are:

At line:1 char:21
+ >> foreach($vssFile in (get-childitem "$directoryToUpdate\*.vss" -Rec ...
+                     ~~
Unexpected token 'in' in expression or statement.
At line:1 char:20
+ >> foreach($vssFile in (get-childitem "$directoryToUpdate\*.vss" -Rec ...
+                    ~
Missing closing ')' in expression.
At line:19 char:73
+ ... ch($vssFile in (get-childitem "$directoryToUpdate\*.vss" -Recurse")){
+                                                                        ~
Unexpected token ')' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken
Mofi
  • 46,139
  • 17
  • 80
  • 143
  • 1
    Please help us make clear what you want to ask. https://stackoverflow.com/help/how-to-ask – harper Jan 17 '23 at 06:03
  • You can help PowerShell to find the end of a variable name is shown here: https://stackoverflow.com/questions/30543753/powershell-variable-in-replacement-string-with-named-groups – harper Jan 17 '23 at 06:04
  • 1
    Remove the double-quote after `-Recurse` on line 3 – Daniel Jan 17 '23 at 06:59

1 Answers1

1

I would say you are overcomplicating this. Here is a slight refactor of your code.

$visio = New-Object -com Visio.Application

 Get-ChildItem -Path 'C:\office\Stencils\*.vss' -Recurse | 
 ForEach-Object {
    "Working on $($PSItem.Name)"

    $doc          = $visio.Documents.Open($PSItem.FullName)
    $vssxFileName = [io.path]::ChangeExtension($PSItem,'.vssx')

    $doc.SaveAs($VSSXFileName)
    $doc.close()
 }
postanote
  • 15,138
  • 2
  • 14
  • 25