EDUCBA

EDUCBA

MENUMENU
  • Blog
  • Free Courses
  • All Courses
  • All in One Bundle
  • Login
Home Data Science Data Science Tutorials PowerShell Tutorial PowerShell Get-Item

PowerShell Get-Item

Priya Pedamkar
Article byPriya Pedamkar

Updated March 27, 2023

powershell get item

Introduction to PowerShell Get-Item

To get any item from any defined location we can use the command Get-Item. With this command we can not get the content of the item, I mean with this command we can not get content directly, but we can get content by using wildcard. To get the content from the item we need to use a wildcard for it, for example (*) to all the contents of the item. This command will be useful in case if you want to navigate through all the available data stores. The main purpose of this command it will allow us to know any available items of any folder or directories from any directories.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Syntax & Parameters in PowerShell Get-Item

Below are the syntax:

Syntax #1

Get-Item
[-Path] <String path for item location>
[-Filter <string filter condition for path>] [-Include <string name of path to include for getting item details>] [-Exclude <string name of path to exclude for getting item details>] [-Force<find the hidden or read only item>] [-Credential <PSCredential>] [-Stream <get the alternate stream of NTFS file>] [<CommonParameters>]

Syntax #2

Get-Item
-LiteralPath <String of exact path name>
[-Filter <string filter condition for path>] [-Include <string name of path to include for getting item details>] [-Exclude <string name of path to exclude for getting item details>] [-Force<find the hidden or read only item>] [-Credential <PSCredential>] [-Stream <get the alternate stream of NTFS file>] [<CommonParameters>]

Parameters

Below are the parameters in PowerShell Get-Item:

1. Credential

This parameter used for the secure execution of the command. Even by using force command one can not break or skip it. But this parameter is not supported by any PowerShell installed providers. If we are really interested in using this command along with Invoke-Command. We have already discussed this command. To know more about Invoke-Command you can refer to the previous section. In this command, we can use an argument like User1, or we can use Domain1/user1.Once you run this command along with the user name it will display a prompt and it will ask for the password. This command introduced in PowerShell version 3.0.

2. Exclude

It defined an array of items that command will execute while running. This parameter will take the path as it’s the parameter value. We can enter path params or we can also specify the pattern for it. The path pattern can be like *.txt.Remember the include command will work better if we will use wildcard character with it for operation, for example, \ranjan\* here character used in wildcard represents contents of the path.

3. Filter

It defines the filtered path to locate the item. We are able to use filter param with PowerShell because it has installed provider FileSystem.We can learn more about FileSystem in about_Wildcard. Always filters are a better option than any other because the provider works when the command received objects instead of after receiving the objects.

4. Force

Many times we will face a situation where we will not be able to fetch items, because of read-only access or any items are hidden file. In such type of situation, we can use this command. How it’s implementation will be done is totally depend on the providers. If you wanted to learn more about the providers please read about_Provider. Force command can not skip the security restrictions. Security restriction means user credential and a valid login user.

5. Include

It defined a string array of items that command will execute while running. This parameter will take the path as it’s the parameter value. We can enter path params or we can specify the pattern also for it. The path pattern can be like *.txt.We can also use a wildcard for it. Remember the include command will work better if we will use wildcard character with it for operation, for example, \ranjan\* here character used in wildcard represents contents of the path.

6. LiteralPath

We have seen many ways to locate the path of items, this one of the ways to locate the path of items. The only thing in this way to locate the path is that we can not use a wildcard as pathname example we can not use “*”. So basically we have to pass the exact path which is as it is typed. The good thing about the literal path is, we can use escape characters. In case if we are using escape character in -LiteralPath we must use a single quotation to notify the Powershell about escape character.

7. Path

Path defines the location of an item. Which the help of this command we can get the item. In the previous params which is LiteralPath, we learned that we have to use an exact path to locate the item, here in case path we can also use a wildcard as path like (*). This is a required parameter. The name of the parameter path is not a required field that means optional.

8. Stream

With the help of this command, we get another or alternate stream of NTFS file from your system files. We just have to give a stream name in this case . Name of the stream can be wildcard also, for example, we can use (*) as the stream name. This command is mainly made for the file system so in case of folders it will not work. A provider called FileSystem which adds the stream to command Get-Item. These streams are dynamic in nature which add by provider FileSystem to command Get-item.

Examples to Implement PowerShell Get-Item

The following are examples to implement:

Example #1

In this example, we will see the current directories’ details.

Code:

Get-Item *

Output:

PowerShell Get-Item - 1

Example #2

In this example, we are fetching the directories by specifying the pathname. See the below example along with the screen of the experiment.

Code:

Get-Item ./ranjan1

Output:

specifying the pathname

Example #3

Till we have seen that by writing path names or current directories we were only able to fetch the folder path but as I said in starting that if we want to get the contents of the directories we need to use a wild card. See the example below where we are passing path names with a wildcard (*) and in output, we are getting all of the contents of the directories.

Code:

Get-Item ./ranjan*

Output:

PowerShell Get-Item - 3

Example #4

In the below example we want to see the last modified or open this directory. Their many properties we can see them in documentations. Please follow the example below along with screens.

Code:

(Get-Item ./ranjan).LastAccessTime

Output:

 last modified or open this directory

Example #5

We have discussed parameters like excluding and include, I am giving an example of excluding. In the below example we are fetching items in the current directory, it returns Desktop. Because we are excluding “W*” once we used “*d” it returns nothing as Desktop starts with D and we are excluding “d”.Please see the below example with the experiment screen.

Code:

Get-Item . -Exclude "w*"
Get-Item . -Exclude "d*"

Output:

PowerShell Get-Item - 5

Recommended Articles

This is a guide to PowerShell Get-Item. Here we discuss Syntax, parameters, examples to implement PowerShell Get-Item. You can also go through our other related articles to learn more –

  1. Power BI Tooltips
  2. PowerShell Tools
  3. PowerShell Sort-Object
  4. PowerShell Convert to String | Parameters
All in One Excel VBA Bundle
500+ Hours of HD Videos
15 Learning Paths
120+ Courses
Verifiable Certificate of Completion
Lifetime Access
Financial Analyst Masters Training Program
2000+ Hours of HD Videos
43 Learning Paths
550+ Courses
Verifiable Certificate of Completion
Lifetime Access
All in One Data Science Bundle
2000+ Hour of HD Videos
80 Learning Paths
400+ Courses
Verifiable Certificate of Completion
Lifetime Access
All in One Software Development Bundle
5000+ Hours of HD Videos
149 Learning Paths
1050+ Courses
Verifiable Certificate of Completion
Lifetime Access
Primary Sidebar
All in One Data Science Bundle2000+ Hour of HD Videos | 80 Learning Paths | 400+ Courses | Verifiable Certificate of Completion | Lifetime Access
Financial Analyst Masters Training Program2000+ Hours of HD Videos | 43 Learning Paths | 550+ Courses | Verifiable Certificate of Completion | Lifetime Access
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more