1

I have a script that creates a csv file which I then go open to get the information I am looking for. Is there a way to add to the script so that the file opens immediately as well as saves in the specified location?

Get-ADComputer -Filter { Enabled -eq $true } -Properties Name -SearchBase          
"DC=REMOVED,DC=com" | 
Select Name |
? {$_. Name -like "X*" } |
Export-Csv "C:\scripts\Computers.csv"
Mason Evans
  • 121
  • 3
  • 4
  • 12
  • Open in what program? `c:\pathToProgram.exe C:\scripts\Computers.csv` will likely work... – Austin T French Oct 20 '16 at 19:41
  • Excel. The path to Excel.exe for me is: C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.exe so would I use that followed by the path of the script? I tried that just now to check and wasn't finding any success. – Mason Evans Oct 20 '16 at 19:46
  • Try `start C:\scripts\Computers.csv` –  Oct 20 '16 at 20:02

1 Answers1

7

Add this quick snippet to the end of your code:

Invoke-Item "C:\scripts\Computers.csv"

If you have Excel automatically configured to support/open .csv files, it should open automatically.

EDIT: Note that this isn't available in Powershell 2.0 - only 3.0+

gravity
  • 2,175
  • 2
  • 26
  • 34