# get-childitem variable

**URL:** <https://forums.powershell.org/t/get-childitem-variable/6144>\
**Category:** PowerShell Help\
**Created:** [April 6, 2016, 6:59am UTC](https://forums.powershell.org/t/get-childitem-variable/6144 "2016-04-06T06:59:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![arjen-nap](https://avatars.discourse-cdn.com/v4/letter/a/13edae/32.png) [@arjen-nap](https://forums.powershell.org/u/arjen-nap)\
**Post date:** [April 6, 2016, 6:59am UTC](https://forums.powershell.org/t/get-childitem-variable/6144/1 "2016-04-06T06:59:41Z")

</div>

I’m trying to use gci on the results of an earlier gci.  
Let me explain myself.  
I have to search and delete certain files in the homefolders of users.

So I did first $users = gci c:\homefolders -name to get all the names off the userdirs. After this I want to use gci $users\specificdir or something but I cant find out if I have to use foreach command for that. I’m stuck.

I’m also using this construction to don’t overload the server

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [April 6, 2016, 7:10am UTC](https://forums.powershell.org/t/get-childitem-variable/6144/2 "2016-04-06T07:10:38Z")

</div>

$users, in that case, is a collection of File and/or Folder objects. You’re passing those to the -Path parameter of GCI, which does not accept File/Folder objects.

You probably meant…

$users = Get-ChildItem c:\homefolders -Folder | Select -Expand Name

Or something along those lines, so that $users contains only folder names as String objects. I’m not certain the above is 100% what you’re after as I’m not 100% clear on what you’re doing, but hopefully this can help you.

---

<div class="post-metadata">

**Author:** ![jonathan-warnken](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/jonathan-warnken/32/469_2.png) [@jonathan-warnken](https://forums.powershell.org/u/jonathan-warnken)\
**Post date:** [April 6, 2016, 7:16am UTC](https://forums.powershell.org/t/get-childitem-variable/6144/3 "2016-04-06T07:16:34Z")

</div>

You will need to use the foreach command because the 1st command could contain an unknown number of objects.

```
$users = gci c:\homefolders -name
foreach($user in $users){gci $user.pspath}
```

---

<div class="post-metadata">

**Author:** ![arjen-nap](https://avatars.discourse-cdn.com/v4/letter/a/13edae/32.png) [@arjen-nap](https://forums.powershell.org/u/arjen-nap)\
**Post date:** [April 6, 2016, 8:06pm UTC](https://forums.powershell.org/t/get-childitem-variable/6144/4 "2016-04-06T20:06:55Z")

</div>

Thanks Jonathan! With your help I could finish my script.

```
$users = gci c:\homefolders -name
$sign = foreach($user in $users){gci $user\Pwrmenu -filter "*outsig*" -name}
foreach ($del in $sign) {remove-item $del.pspath}
```

now I can hunt down all the files with outsig in it and delete it.  
If I do this with the normal explorer it takes me 5 mins maybe and now just 5 seconds :)… love it!

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:41pm UTC](https://forums.powershell.org/t/get-childitem-variable/6144/5 "2024-05-16T20:41:41Z")

</div>

Closed on May 16, 2024, 8:41pm UTC


