PowerShell Invoke-Item Cmdlet
My main use for Invoke-Item is when my PowerShell script has just created a file, and I am itching to view its formatted contents. Another use is running executables.
Topics for the Invoke-Item Cmdlet
To get a feel of Invoke-Item let us compare it with Get-Content:
Note 1: Invoke-Item uses notepad to view win.ini; this is because of the file association.
Note 2: Get-Content displays the raw contents.
As we will see in the next example, Invoke-Item comes into its own with heavily formatted data, such as html.
Preamble, WinKey +r, iexplore works fine, but how do you achieve the same result in PowerShell.
#Problem: In PowerShell this plain command does not work.
# Solution: Call for PowerShell's Invoke-Item
Note 3: I find that Invoke-Item needs the full path.
Note 4: A better way of launching a program may be Start-Process
SolarWinds' Network Performance Monitor will help you discover what's happening on your network. This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.
What I like best is the way NPM suggests solutions to network problems. Its also has the ability to monitor the health of individual VMware virtual machines. If you are interested in troubleshooting, and creating network maps, then I recommend that you try NPM now.
Suppose you have just created a web page using PowerShell's ConvertTo-Html cmdlet. Your next step is to see whether the output displays as you expected. Instead of ferreting around with explorer, why not append Invoke-Item?
Scenario: You want a list of running services that you cannot stop. Furthermore, you want to publish the file to the intranet.
# PowerShell Invoke-Command example to find services you cannot
Note 5: What makes this Invoke-Item task easy is the use of the $File variable.
Another Invoke-Item Example
In this example I employ Invoke-Item solely to check the xml file has been created as expected.
$File = "D:\PShell\ProcUnique.xml"
This Engineer's Toolset v10 provides a comprehensive console of 50 utilities for troubleshooting computer problems. Guy says it helps me monitor what's occurring on the network, and each tool teaches me more about how the underlying system operates.
There are so many good gadgets; it's like having free rein of a sweetshop. Thankfully the utilities are displayed logically: monitoring, network discovery, diagnostic, and Cisco tools. Try the SolarWinds Engineer's Toolset now!
# Employ Get-Help to investigate the syntax of Invoke-Item
Note 6: Help reveals that Invoke could work with wildcards in the path,
however, I rarely use it to open multiple files, for example:
Where Next: Check Other Members of the Invoke Family
Invoke is a rarely used verb in general English or in PowerShell, let me introduce to the rest of this select family:
# List members of PowerShell's Invoke family of cmdlets
Summary of PowerShell's Invoke-Item
My tasks for Invoke-Item are when my script has just created a file, and I wish to view its contents. I find that appending this cmdlet to a script saves me having to open explorer.
If you like this page then please share it with your friends
See more Microsoft PowerShell tasks:
Please email me if you have a better example script. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.