Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

powershell script to remove files on a list of remote computers

Posted on 2012-03-14
5
Medium Priority
?
1,161 Views
Last Modified: 2012-03-15
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}}
0
Comment
Question by:WaywardS0n
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
SieQ earned 2000 total points
ID: 37720527
Try this first
get-content z:\input2.txt | foreach {get-childitem "\\$_\c$\documents and settings"  -include fs_action* -recurse| foreach {Write-host $_.fullname}}

if works
get-content z:\input2.txt | foreach {get-childitem "\\$_\c$\documents and settings"  -include fs_action* -recurse| foreach {remove-item $_.fullname}}
-whatif  - is optional
0
 

Author Comment

by:WaywardS0n
ID: 37724512
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
0
 
LVL 2

Expert Comment

by:SieQ
ID: 37724820
and if you would skip "-include" option, does it list something ?
and do you have rights to access "$" shares
are these shares available ?
0
 

Author Comment

by:WaywardS0n
ID: 37724903
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?
0
 

Author Closing Comment

by:WaywardS0n
ID: 37724910
If searching 'hidden' folders don't forget to add the -Force option to the Get-ChildItem cmdlet.
0

Featured Post

Looking for the Wi-Fi vendor that's right for you?

We know how difficult it can be to evaluate Wi-Fi vendors, so we created this helpful Wi-Fi Buyer's Guide to help you find the Wi-Fi vendor that's right for your business! Download the guide and get started on our checklist today!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question