Questions tagged [get-childitem]

Get-ChildItem is a powershell cmdlet that gets the items and child items in one or more specified locations.

Get-ChildItem is a powershell cmdlet that gets the items and child items in one or more specified locations. If the item is a container, it gets the items inside the container, known as child items. You can use the Recurse parameter to get items in all child containers.

A location can be a file system location, such as a directory, or a location exposed by a different Windows PowerShell provider, such as a registry hive or a certificate store.

Output

  • System.Object
    The type of object that Get-ChildItem returns is determined by the objects in the provider drive path.

  • System.String
    If you use the Name parameter, Get-ChildItem returns the object names as strings.

520 questions
45
votes
3 answers

Limiting Powershell Get-ChildItem by File Creation Date Range

I use a Powershell command to generate a CSV report of certain file types. My goal is to find out how many were added during a particular date range. Right now, the script finds everything and I sort by date to find my number. I'd like to modify the…
Nathan
  • 766
  • 2
  • 9
  • 19
40
votes
5 answers

Use PowerShell to generate a list of files and directories

I'm writing a PowerShell script to make several directories and copy a bunch of files together to "compile" some technical documentation. I'd like to generate a manifest of the files and directories as part of the readme file, and I'd like…
YetAnotherRandomUser
  • 1,320
  • 3
  • 13
  • 31
37
votes
5 answers

How can Get-ChildItem be tested for no results (zero files)?

I'm stumped here on what seems to be a simple problem; so sorry for any bone-headed-ness over here. I have script that cleans up defunct backup files. After identifying the files I loop over and print out what's being dumped. My problem arises…
EBarr
  • 11,826
  • 7
  • 63
  • 85
33
votes
1 answer

Get-ChildItem and non-breaking space

While working on my file servers, I have noticed one strange folder that broke my script. Folder has name consisting of only one character with ascii value 160 (non-breaking space, NBSP). Visually that name is the same as space character. Briefly, I…
Igor
  • 1,349
  • 12
  • 25
24
votes
5 answers

Combine the results of two distinct Get-ChildItem calls into single variable to do the same processing on them

I'm trying to write a PowerShell script to build a list of files, from several directories. After all directories have been added to the main list, I'd like to do the same processing on all files. This is what I have: $items = New-Object…
Nate
  • 30,286
  • 23
  • 113
  • 184
21
votes
2 answers

Adding the file sizes of Get-ChildItem listing

My goal is to figure out how much space all images on my network drives are taking up. So my command to retrieve a list of all images is this: Get-ChildItem -recurse -include *jpg,*bmp,*png \\server01\folder Then I would like to just retrieve…
user2517266
  • 335
  • 1
  • 2
  • 6
21
votes
3 answers

Powershell Get-ChildItem -Filter operates differently to Where clause with same value

I have a folder on a server called MyFolder. There are additional folders called MyFolder.1, MyFolder.2, MyFolder.3 etc. If I run: gci C:\Sample | ? { $_.Name -like "MyFolder.*" } I get the expected output: Directory: C:\Sample Mode …
Kieranties
  • 697
  • 1
  • 4
  • 14
19
votes
1 answer

How to find files in directories with certain name using Get-ChildItem?

I have a project folder called topfolder and I want to find all files in all subfolders that match a certain pattern, e.g. when the folder contains foo anywhere in its name, I want to list all files inside it. I tried something like: gci .\topfolder…
Borek Bernard
  • 50,745
  • 59
  • 165
  • 240
18
votes
5 answers

Locating all subdirectories matching a string or partial string

I basically need to set a variable to a folder path without knowing the full path. My issue is I need to find a directory called "DirA" for example. But this directory could either be located in "DirB\" or "DirB\DirC" and sometimes the directory…
Dewi Jones
  • 785
  • 1
  • 6
  • 18
15
votes
4 answers

Select second or third object / element

I want to select the second/third/forth object of a Get-ChildItem statement in my PowerShell script. This gives me the first: $first = Get-ChildItem -Path $dir | Sort-Object CreationTime -Descending | Select-Object -First 1 This…
Tobi123
  • 508
  • 4
  • 8
  • 25
15
votes
5 answers

Get-ChildItem and Copy-Item explanation

Why does gci $from -Recurse | copy-item -Destination $to -Recurse -Force -Container not behave in the same way as copy-item $from $to -Recurse -Force ? I think it should be the same, but somehow it's not. Why?
Dejan Dakić
  • 2,418
  • 2
  • 25
  • 39
14
votes
2 answers

Is Get-ChildItem -Recurse broken when there are square brackets in the input path?

OK, so I feel like this must be a bug in PowerShell, but I wanted to see if you guys think this sounds broken. It's quite an easy thing to reproduce, but I can see why it might not be a particularly common use case. The steps I've put below aren't…
Richard Irons
  • 1,433
  • 8
  • 16
14
votes
5 answers

How to use wildcards with directories in PowerShell's Get-ChildItem -Exclude cmdlet

For a simple example, let's say I have a folder, Root, with three folders in it; Folder1, Folder2, and Folder3. Each of these folders (including Root) has a bunch of files in them, including .pdb files. I want to use the PowerShell Get-ChildItem…
deadlydog
  • 22,611
  • 14
  • 112
  • 118
13
votes
3 answers

How do I merge two "lists" in PowerShell when one list might be just one item from Get-Item?

I am using Get-ChildItem to fetch locally installed certs. Then I'd like to delete these certs from my local certificate store. If I execute the script below it will work when there is more than one item returned in both the Get-ChildItem queries.…
noopman
  • 660
  • 1
  • 4
  • 15
12
votes
6 answers

Confused with -Include parameter of the Get-ChildItem cmdlet

From documentation: -Include Retrieves only the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as "*.txt". Wildcards are permitted. The Include parameter is effective only…
alex2k8
  • 42,496
  • 57
  • 170
  • 221
1
2 3
34 35