Solved

Script to delete files from user profile

Posted on 2013-06-05
5
1,314 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

You may have a outside contractor who comes in once a week or seasonal to do some work in your office but you only want to give him access to the programs and files he needs and keep privet all other documents and programs, can you do this on a loca…
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
This Micro Tutorial will give you a basic overview of Windows Live Photo Gallery and show you various editing filters and touches to photos you can apply. This will be demonstrated using Windows Live Photo Gallery on Windows 7 operating system.

809 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