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 $report
复制代码 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"'
复制代码 This won't work, however, if you require variable expansion. Instead, use:- Start Start-Process Excel -ArgumentList """$report"""
复制代码 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'
复制代码 To list all applications registered in App Paths, use:- Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths'
复制代码
|