Avatar of WaywardS0n
WaywardS0n
 asked on

powershell script to remove files on a list of remote computers

what I'm trying to do is...
I have a file with computers names in the following format

computername1
computername2
computername3

I need to go to each computer, search the directory of each user to locate files that start with fs_action and delete them. Still trying to get a handle on powershell. Here's where I am... doesn't seem to locate / list them. Any help?

$a = get-content z:\input2.txt | foreach ($a) {$b=get-childitem "\\$_\c$\documents and settings" -include fs_action* -recurse | foreach ($b) {remove-item $b.fullname -whatif}}
Visual Basic.NETPowershellScripting Languages

Avatar of undefined
Last Comment
WaywardS0n

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
SieQ

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
WaywardS0n

ASKER
Nothing was returned. I even pared it down to...
get-childitem "\\actualcomputername\c$\documents and settings"  -include fs_action* -recurse| foreach {Write-host $_.fullname}
and still nothing...

These files are located under multiple user profiles.
C:\documents and settings\multiplenames\Local Settings\Temp
these are files verified to reside under a couple of the users.

fs_action_609.bat
fs_action_609.finish
fs_action_609.res

I'm running this from a Windows 7 box checking XP boxes.

Thanks for the assistance so far...

David
SieQ

and if you would skip "-include" option, does it list something ?
and do you have rights to access "$" shares
are these shares available ?
WaywardS0n

ASKER
After implementing the testing changes you mentioned (skipping the -Include), I noticed that not all the directories were listed, its not -recursing hidden folders. C:\documents and settings\multiplenames\Local Settings is/are hidden folders.
So I added the -Force option and now I'm getting results.

Thanks for the assistance!

David

PS, any workarounds for the....
"Get-ChildItem : The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters."
error message?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
WaywardS0n

ASKER
If searching 'hidden' folders don't forget to add the -Force option to the Get-ChildItem cmdlet.