removing Windows Profiles

Hello Folks,

i'm trying to create a script to remove specific profiles from remote PC PCs, this is what i have so far,

(Get-WmiObject -ComputerName COMPUTER1 -v Win32_UserProfile |Select-Object localpath | Where-Object {$_.LocalPath -like "C:\users*" -and $_.LocalPath -notmatch "Administrator

Open in new window

but i get an error:
Remove-WmiObject : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any
of the parameters that take pipeline input.

can anybody kindly take a look and see what am I be missing? or if anybody have a better idea?
ivan rosaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

The issue is the "Select-Object localpath" - after that, all you're passing down the pipeline is a custom object with one single property "localpath", and Remove-WmiObject for the obvious reasons has no idea what to do with that.
Try it like that; I added a -WhatIf to the Remove-Object; remove it to run it for real:
Get-WmiObject -ComputerName COMPUTER1 -Class Win32_UserProfile | Where-Object {$_.LocalPath -like "C:\users*" -and $_.LocalPath -notmatch "Administrator"} | Remove-WmiObject -WhatIf

Open in new window

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
ivan rosaAuthor Commented:
yeah your theory is correct! thanks for your assistance!
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

From novice to tech pro — start learning today.