PowerShell Command.

Hi Guys,

I have a script that I'm trying to run. See below.

$BaseDir = 'E:\Test\'

$Users = gci -path $baseDir #| where ($_.Name -match "Jane.Mcintosh")

Get-ChildItem -path $BaseDir\$Users\desktop -Recurse -Hidden  #| Where-Object {($_.PSIsContainer ) -AND ($_.Name -EQ '$Recycle.Bin')}

Now the issue is that when i run  the above it does not find each folder individually it as if it finding all folders as one .

See below error

Get-ChildItem : Cannot find path 'E:\Test\gf.test1 gf.test4\' because it does not exist.

Its should list each folder individually.
gfsupportAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

footechCommented:
Yes, for $Users you are saving a collection of filesystem objects (assuming there's more than one subfolder and/or file).  You would then have to loop through the array if you want to process each item in that array.
$Users = gci -path $baseDir
$Users | ForEach { Get-ChildItem -path "$BaseDir\$($_.name)\desktop" -Recurse -Hidden }

Open in new window


For $Users, if you know you're only interested in one property (like the name), use Select-Object to narrow it down, as it can make using the contents easier later on.
$Users = gci -path $baseDir | Select -expandProperty name
$Users | ForEach { Get-ChildItem -path "$BaseDir\$_\desktop" -Recurse -Hidden }

Open in new window


You could combine it all into one pipeline.
Get-ChildItem -path $baseDir | ForEach { Get-ChildItem -path "$($_.fullname)\desktop" -Recurse -Hidden }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gfsupportAuthor Commented:
Thank you for your help, i now see where i went wrong.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.