PowerShell Get-Item Cmdlet
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
In the last blog post, we have discussed Rename-Item cmdlet in PowerShell.
https://cloudaffaire.com/powershell-rename-item-cmdlet/
In this blog post, we will discuss Get-Item cmdlet in PowerShell. You can use Get-Item cmdlet to get an item in a specific location. Using Get-Item cmdlet, you can get item details for files, directories, and registry keys. Get-Item does not get the content of the items, it only returns item property. Get-Item cmdlet returns only a limited set of item properties, to get the complete list of item property use Get-ItemProperty cmdlet.
Get-Item Cmdlet Syntax:
1 2 3 4 5 6 7 8 9 10 |
## Get-Item ## [-Path] ## [-Filter ## [-Include ## [-Exclude ## [-Force] ## [-Credential ## [-UseTransaction] ## [-Stream ## [ |
Get-Item Cmdlet Argument List:
- –Credential: To impersonate another user or elevate your credentials.
- –Exclude: Specifies, as a string array, an item or items that this cmdlet excludes in the operation. The value of this parameter qualifies the Path parameter.
- –Filter: Specifies a filter to qualify the Path parameter. The FileSystem provider is the only installed PowerShell provider that supports filters.
- –Force: Forces the cmdlet to remove items that cannot otherwise be changed, such as hidden or read-only files or read-only aliases or variables.
- –Include: Specifies, as a string array, an item or items that this cmdlet includes in the operation. The value of this parameter qualifies the Path parameter.
- –LiteralPath: Specifies a path to one or more locations. The value of LiteralPath is used exactly as it is typed. No characters are interpreted as wildcards.
- –Path: Specifies a path of the items being removed. Wildcard characters are permitted.
- –Stream: Gets the specified alternate NTFS file stream from the file. Enter the stream name. Wildcards are supported.
- –UseTransaction: Includes the command in the active transaction. This parameter is valid only when a transaction is in progress.
PowerShell Get-Item Cmdlet:
Get Properties Of A Variable In PowerShell:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#################################### ## PowerShell | Cmdlet | Get-Item ## #################################### ## PowerShell Latest Version (5) ## create a variable, file, directory and registry key $myvar = "Hello World" New-Item -Path HKCU:\Software -Name MyRegKey -Value "Hello World" New-Item -ItemType Directory -Path C:\MyDir\ New-Item -ItemType Directory -Path C:\MyDir\MyDir1 New-Item -ItemType File -Path C:\MyDir\MyFile1 ## get item property for a variable Get-Item -Path Variable:myvar Get-Item -Path Variable:myvar | Select-Object * |
Get Properties Of A Directory In PowerShell:
1 2 3 4 |
## get item property for a directory Get-Item -Path C:\MyDir\MyDir1 Get-Item -Path C:\MyDir\MyDir1 | Select-Object * |
Get Directory Listing Using Get-Item Cmdlet In PowerShell:
1 2 3 |
## get directory listing using get-item Get-Item -Path C:\MyDir\* |
Get Properties Of A File In PowerShell:
1 2 3 4 |
## get item property for a file Get-Item -Path C:\MyDir\MyFile1 Get-Item -Path C:\MyDir\MyFile1 | Select-Object * |
Get Properties Of A Registry Key In PowerShell:
1 2 3 4 5 6 7 8 9 10 |
## get item property for a registry key Get-Item -Path HKCU:\Software\MyRegKey Get-Item -Path HKCU:\Software\MyRegKey | Select-Object * ## remove the items created for this demo Remove-Item -Path Variable:myvar Remove-Item -Path HKCU:\Software\MyRegKey Remove-Item -Path C:\MyDir -Recurse |
Hope you have enjoyed this article. In the next blog post, we will discuss Set-Item cmdlet in PowerShell.
To get more details on PowerShell, kindly follow below official documentation