Solved

Script to delete files from user profile

Posted on 2013-06-05
5
1,282 Views
Last Modified: 2013-06-19
Hello,

Network:

Windows Server 2008 R2
Windows 7 Pro x64
Roaming Profiles

Problem:

I've got a user profile that contains files which have a path and filename that are to long to be handled by the operating system. So I can't delete the files. I've got GPO's running that should clean up these files during logoff. Logging off takes very long time, and then i get an error message that the profile could not sync properly. That's because the policy is unable to delete the files.0

Can I delete the files in question somehow? With a powershell script maybe?
0
Comment
Question by:SvenIA
  • 2
  • 2
5 Comments
 
LVL 10

Expert Comment

by:Sam Simon Nasser
ID: 39221394
can you explain this:
have a path and filename that are to long to be handled by the operating system

so the user desktop for example is set to c:\users\userX\desktop and not X:\Server\UserX\Desktop
0
 
LVL 7

Author Comment

by:SvenIA
ID: 39221409
Sure i can;

Profile
That folder contains files which have names that are to long. They cannot be deleted.

The policy that is configured to delete these temp files on logoff, cannot delete these files either. That's why profile sync times out when logging off.

The profile is way to large. So I want to cleanup.
0
 
LVL 10

Assisted Solution

by:Sam Simon Nasser
Sam Simon Nasser earned 250 total points
ID: 39221578
i once did it on windows XP, but in different way:
i created  roaming profile, that sync ONLY My Documents, Favorites and Desktop (these 3 are backed on the server), other items will be stored locally.

give it a try, in your way, let the profile sync everything EXCEPT the appData folder (only appData will be stored locally, other folders are on the roaming profile on the server.)
0
 
LVL 10

Accepted Solution

by:
CSI-Windows_com earned 250 total points
ID: 39224135
Try the rmdir (rd) command which will remove files as well as long as you give it all the below parameters  (it also continues when it hits files that cannot be removed - hand for temp clean up):

rmdir "d:\profiles\heinejas.v2\appdata\local\microsoft\windows\temporary internet files" /s /q

Another possible work around:

subst r: d:\profiles\heinejas.v2\appdata\local\microsoft\windows

rmdir "r:\temporary internet files" /s /q

And some custom powershell code for long paths handling:

http://huddledmasses.org/long-path-module-experimental-io/
0
 
LVL 7

Author Closing Comment

by:SvenIA
ID: 39259849
I created a connection directly to the users profile folder. In that way the path is shorter. Then i could delete the files.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

706 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now