Opening the output file automatically

时间:2016-10-20 19:37:10

标签: powershell

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"

1 个答案:

答案 0 :(得分:5)

将此快速代码段添加到代码的末尾:

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

如果Excel自动配置为支持/打开.csv文件,则应自动打开。

编辑:请注意,这在Powershell 2.0中不可用 - 仅3.0 +