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
$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.
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!