Moving or Deleting Directories with Command Prompt

L

lforbes

Hi,

I run a Windows 2003 Domain with hundreds of XP and 2K clients. Even
though the Logons to Cache is set to "0" and the "delete roaming
profiles on logoff" is checked, the machines are STILL caching
roaming profiles.

Most of the time it is just the Application Data folder but often it
is the entire profile. The XP machines are the worst offenders.

I have thousands of users logging onto different machines all the time
so I am accumulating hundreds of profile folders in the Documents and
Settings folders on the machines. All I want there are Administrator,
All Users, Default User, LocalService and NetworkService.

I wanted to create startup batch file to delete them but it doesn’t
seem that the Command line does such a thing.

RMDIR works only if I specifiy the exact directory name. Eg. a*.*
doesn’t work.

I thought I could Move the directories into another directory and
delete that, BUT the Move Command only moves files.

Does anyone know of a vbscript or any trick to delete all BUT the
Administrator, All Users, Default User, LocalService and
NetworkService Profile Folders.

Cheers,

Lara

PS. The Reason I don’t want cached credentials is my users have
mandatory profiles with lots of Group Policies. If a profile is
cached, it will allow logon even if the Domain is not available and
"therefore" the Group Policies don’t apply.
 
P

Pegasus \(MVP\)

lforbes said:
Hi,

I run a Windows 2003 Domain with hundreds of XP and 2K clients. Even
though the Logons to Cache is set to "0" and the "delete roaming
profiles on logoff" is checked, the machines are STILL caching
roaming profiles.

Most of the time it is just the Application Data folder but often it
is the entire profile. The XP machines are the worst offenders.

I have thousands of users logging onto different machines all the time
so I am accumulating hundreds of profile folders in the Documents and
Settings folders on the machines. All I want there are Administrator,
All Users, Default User, LocalService and NetworkService.

I wanted to create startup batch file to delete them but it doesn't
seem that the Command line does such a thing.

RMDIR works only if I specifiy the exact directory name. Eg. a*.*
doesn't work.

I thought I could Move the directories into another directory and
delete that, BUT the Move Command only moves files.

Does anyone know of a vbscript or any trick to delete all BUT the
Administrator, All Users, Default User, LocalService and
NetworkService Profile Folders.

Cheers,

Lara

PS. The Reason I don't want cached credentials is my users have
mandatory profiles with lots of Group Policies. If a profile is
cached, it will allow logon even if the Domain is not available and
"therefore" the Group Policies don't apply.

--
Posted using the http://www.WindowsForumz.com/ interface, at author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.WindowsForumz.com/Genera...Directories-Command-Prompt-ftopict249184.html
Visit Topic URL to contact author (reg. req'd). Report abuse:
http://www.WindowsForumz.com/eform.php?p=763446

Try this:

@echo off
pushd "C:\Documents and Settings"

set Exempt=*Administrator* *All Users* *Default User* *LocalService*
*NetworkService*
for /d %%a in (*.*) do echo %Exempt% | find /i "*%%a*" > nul || echo rd /s
/q "%%a"

popd

Remove the "echo" instruction to activate the script!
 
L

lforbes

Pegasus said:
abuse:
http://www.WindowsForumz.com/eform.php?p=763446

Try this:

@echo off
pushd "C:Documents and Settings"

set Exempt=*Administrator* *All Users* *Default User*
*LocalService*
*NetworkService*
for /d %%a in (*.*) do echo %Exempt% | find /i "*%%a*" > nul
|| echo rd /s
/q "%%a"

popd

Remove the "echo" instruction to activate the script!

Hi,

It is a pretty cool string. I am getting a "the system cannot find
the file specified" error. It is probably something simple like a
quote or a space. Unfortunately this word wraps so it is difficult to
know hard returns from a wrap. I want to delete ALL folders except the
above. I am not sure if this deletes only those starting with "a" or
not. This is my string:

pushd "C:\Documents and Settings"

set Exempt=*Administrator* *All Users* *Default User* *LocalService*
*NetworkService* for /d %%a in (*.*) do %Exempt% | find /i "*%%a*" >
nul || rd /s /q "%%a"

Thanks

Lara
 
P

Pegasus \(MVP\)

lforbes said:
Hi,

It is a pretty cool string. I am getting a "the system cannot find
the file specified" error. It is probably something simple like a
quote or a space. Unfortunately this word wraps so it is difficult to
know hard returns from a wrap. I want to delete ALL folders except the
above. I am not sure if this deletes only those starting with "a" or
not. This is my string:

pushd "C:\Documents and Settings"

set Exempt=*Administrator* *All Users* *Default User* *LocalService*
*NetworkService* for /d %%a in (*.*) do %Exempt% | find /i "*%%a*" >
nul || rd /s /q "%%a"

Thanks

Lara

I'm afraid your line breaks are in the wrong place. Here is my batch file
again, this time with line numbers. Remove the line numbers before
running the batch file!

1 @echo off
2 pushd "C:\Documents and Settings"
3
4 set Exempt=*Administrator* *All Users* *Default User* *LocalService*
*NetworkService*
5 for /d %%a in (*.*) do echo %Exempt% | find /i "*%%a*" > nul || echo rd
/s /q "%%a"
6
7 popd
 
L

lforbes

Pegasus said:
 > > "lforbes" <[email protected]>
wrote in message
 > >   > > > Hi,
  > > >
  > > > I run a Windows 2003 Domain with hundreds
of XP and 2K
 > > clients. Even
  > > > though the Logons to Cache is set to "0"
and the "delete
 > > roaming
  > > > profiles on logoff" is checked, the
machines are STILL
 > > caching
  > > > roaming profiles.
  > > >
  > > > Most of the time it is just the Application
Data folder but
 > > often it
  > > > is the entire profile. The XP machines are
the worst
 > > offenders.
  > > >
  > > > I have thousands of users logging onto
different machines
 > > all the time
  > > > so I am accumulating hundreds of profile
folders in the
 > > Documents and
  > > > Settings folders on the machines. All I
want there are
 > > Administrator,
  > > > All Users, Default User, LocalService and
NetworkService.
  > > >
  > > > I wanted to create startup batch file to
delete them but it
 > > doesn't
  > > > seem that the Command line does such a
thing.
  > > >
  > > > RMDIR works only if I specifiy the exact
directory name. Eg.
 > > a*.*
  > > > doesn't work.
  > > >
  > > > I thought I could Move the directories into
another
 > > directory and
  > > > delete that, BUT the Move Command only
moves files.
  > > >
  > > > Does anyone know of a vbscript or any trick
to delete all
 > > BUT the
  > > > Administrator, All Users, Default User,
LocalService and
  > > > NetworkService Profile Folders.
  > > >
  > > > Cheers,
  > > >
  > > > Lara
  > > >
  > > > PS. The Reason I don't want cached
credentials is my users
 > > have
  > > > mandatory profiles with lots of Group
Policies. If a profile
 > > is
  > > > cached, it will allow logon even if the
Domain is not
 > > available and
  > > > "therefore" the Group Policies don't apply.
  > > >
  > > > --
  > > > Posted using the
http://www.WindowsForumz.com/ interface, at author's
 > > request
  > > > Articles individually checked for
conformance to usenet
 > > standards
  > > > Topic URL:
 > >
http://www.WindowsForumz.com/Genera...Directories-Command-Prompt-ftopict249184.html
  > > > Visit Topic URL to contact author (reg.
req'd). Report
 > > abuse:
 > > http://www.WindowsForumz.com/eform.php?p=763446
 > >
 > > Try this:
 > >
 > > @echo off
 > > pushd "C:Documents and Settings"
 > >
 > > set Exempt=*Administrator* *All Users* *Default
User*
 > > *LocalService*
 > > *NetworkService*
 > > for /d %%a in (*.*) do echo %Exempt% | find /i
"*%%a*" > nul
 > > || echo rd /s
 > > /q "%%a"
 > >
 > > popd
 > >
 > > Remove the "echo" instruction to activate the
script!

I'm afraid your line breaks are in the wrong place. Here is my
batch file
again, this time with line numbers. Remove the line numbers
before
running the batch file!

1 @echo off
2 pushd "C:Documents and Settings"
3
4 set Exempt=*Administrator* *All Users* *Default User*
*LocalService*
*NetworkService*
5 for /d %%a in (*.*) do echo %Exempt% | find /i "*%%a*" >
nul || echo rd
/s /q "%%a"
6
7 popd

Thank You!

I got it to work. I really appreciate your help. This has been bugging
me for years.

Cheers,

Lara
 
P

Pegasus \(MVP\)

lforbes said:
Thank You!

I got it to work. I really appreciate your help. This has been bugging
me for years.

Cheers,

Lara

Thanks for the feedback!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top