Windows PowerShell – Get-Item Cmdlet![PowerShell Get-Item](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMzEiIGhlaWdodD0iNDUiIHZpZXdCb3g9IjAgMCAxMzEgNDUiPjxyZWN0IHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIHN0eWxlPSJmaWxsOiNjZmQ0ZGI7ZmlsbC1vcGFjaXR5OiAwLjE7Ii8+PC9zdmc+)
PowerShell’s Get-ChildItem has a little sister called Get-Item.
Topics – Examples of Get-Item
- Real Life Example: List Environmental Variables
- Research Get-Item’s Parameters
- Find the Alias of Get-Item
- Summary – PowerShell Script to Delete Files
♣
Real Life Example: List Environmental Variables
Our mission here is to list all the Environmental Variables. For example, if we want to research which folder holds the user’s profile files.
# PowerShell script to list Environmental Variables paths
Get-Item env:
Result:
# PowerShell script to list Environmental Variables
Name
——————————————
ALLUSERSPROFILE
APPDATA
CommonProgramFiles
CommonProgramFiles(x86)
CommonProgramW6432
COMPUTERNAME
ComSpec
FP_NO_HOST_CHECK
HOMEDRIVE
HOMEPATH
LOCALAPPDATA
LOGONSERVER
NUMBER_OF_PROCESSORS
OS
Path
PATHEXT
PROCESSOR_ARCHITECTURE
PROCESSOR_IDENTIFIER
PROCESSOR_LEVEL
PROCESSOR_REVISION
ProgramData
ProgramFiles
ProgramFiles(x86)
ProgramW6432
PSModulePath
PUBLIC
SystemDrive
SystemRoot
TEMP
TMP
USERDOMAIN
USERDOMAIN_ROAMINGPROFILE
USERNAME
USERPROFILE
windir
See more about Env:temp
Guy Recommends: A Free Trial of the Network Performance Monitor (NPM)
v11.5
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.
Download a free trial of Solarwinds’ Network Performance Monitor
Research Get-Item’s Parameters
# PowerShell Get-Item parameters.
Clear-Host
Get-Help Get-Item -Full
The principle difference between Get-Item and Get-ChildItem, is the later has a -Recurse parameter.
Differences Between Get-Item and Get-ChildItem
Get-Item returns information on just the object specified, whereas Get-ChildItem lists all the objects in the container. Take for example the C:\ drive.
# PowerShell difference between Get-Item and Get-ChildItem.
Clear-Host
Get-Item C:\
Result:
Mode LastWriteTime Length Name
—- ————- —— —-
d–hs 22/12/2012 13:22 C:\
Get-ChildItem would list all the files and folders under the C:\ Incidentally, you could get the same effect by adding a wildcard.
Get-Item C:\* is the same as plain Get-ChildItem C:\
Conclusion:
While the behaviour of these two cmdlets is very similar, there a few differences which can catch you unawares. My conclusion is stick with Get-ChildItem, I have yet to find a killer use of the shorter Get-Item.
Find the Alias of Get-Item
Get-ChildItem has the famous alias gci, but what of Get-Item?
# PowerShell technique to find an alias.
Clear-Host
Get-Alias -Definition Get-Item
Result: gi
CommandType Name
————— ————
Alias gi -> Get-Item
See also how PowerShell deletes temporary Windows files.
Summary of PowerShell Get-Item
Get-Item does what says: namely it returns the properties of the object specified. In this example it enables us to research the operating system’s environmental variables.
If you like this page then please share it with your friends
See More Windows PowerShell Examples of Real-life Tasks
• PowerShell Tutorials • PowerShell Examples • IpConfig • Get-Counter • PowerShell NetSh
• Monitor Performance – PowerShell • PowerShell temp • PowerShell Delete Temporary files
• PowerShell WOL (Wake-on-Lan) • Services • Change Computer Description Registry
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.