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.

403 questions
38
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
  • 686
  • 2
  • 8
  • 17
34
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,438
  • 7
  • 59
  • 81
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,190
  • 7
  • 21
31
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,087
  • 3
  • 12
  • 27
20
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
  • 28,586
  • 21
  • 107
  • 177
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
  • 43,410
  • 50
  • 148
  • 224
18
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
  • 305
  • 1
  • 2
  • 6
16
votes
2 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
  • 607
  • 1
  • 4
  • 13
12
votes
4 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
  • 19,009
  • 14
  • 91
  • 101
11
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
  • 39,732
  • 56
  • 158
  • 214
11
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,321
  • 5
  • 16
10
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
  • 640
  • 1
  • 4
  • 17
10
votes
3 answers

How to write a PowerShell function to get directories?

Using PowerShell I can get the directories with the following command: Get-ChildItem -Path $path -Include "obj" -Recurse | ` Where-Object { $_.PSIsContainer } I would prefer to write a function so the command is more readable. For…
Tim Murphy
  • 4,822
  • 4
  • 37
  • 47
10
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
  • 440
  • 3
  • 7
  • 22
10
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,318
  • 2
  • 22
  • 38
1
2 3
26 27