This is a part of an on-going blog series written by Adam Gordon. Each week, Adam will walk you through a PowerShell command, showing you when and how to use each one. This week, Adam covers Invoke-Item.
When to use Invoke-Item?
The Invoke-Item cmdlet performs the default action on the specified item. For example, it runs an executable file or opens a document file in the application associated with the document file type.
The default action depends on the type of item and is determined by the PowerShell provider that provides access to the data.
What version of PowerShell am I using?
Get the PowerShell Version from your machine:
$PSVersionTable
This command shows you the PowerShell version information on your machine.
How to use Invoke-Item?
Open a file:
Invoke-Item “C:\PShellTest\Adam.txt”
This command opens the file “Adam.txt” in Notepad. In this case, opening in Notepad is the default action for “.txt” files.
Open all files of a specific type:
This command opens all of the .XML documents in the C:\PShellTest folder. Each document is opened in a new instance of Internet Explorer. In this case, opening in Internet Explorer is the default action for .xml files.
Invoke-Item “C:\PShellTest\*.xml”
Learn last week’s command: Get-PSProvider.
Need PowerShell training? Check out ITProTV’s PowerShell online IT training courses.