This tip provides a nice demonstration of using wildcards to resolve the path to a file or executable. Another method to open a CSV file in Excel takes advantage of the Start-Process cmdlet and the fact that Excel is registered in the App Paths key in the registry. In fact, any application that's registered in App Paths can be lauched using Start-Process in the same manner. | $report = "$env:temp\report.csv" | | Start-Process Excel -ArgumentList $reportCOPY |
Note that if the path to the CSV file includes spaces, it must be passed as a quoted string, so the following would work.Start-Process Excel -ArgumentList '"C:\Users\Some User\Documents\Import File.csv"'COPY This won't work, however, if you require variable expansion. Instead, use:Start Start-Process Excel -ArgumentList """$report"""COPY You can use the following command to determine if Excel is registered in App Paths.Test-Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\excel.exe'COPY To list all applications registered in App Paths, use:Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths'COPY
|