Important Notice: On February 29th, this community will be put into read-only mode. All existing posts will remain but customers will be unable to add new posts or comment on existing. Please feel to join our Community Discord for any questions and discussions.

Clean Temp Files

I'm sure there are some posts about this but I thought I'd share what I came up with.

 

 Package Export:

<?xml version="1.0" encoding="utf-8"?>
<AdminArsenal.Export Code="PDQDeploy" Name="PDQ Deploy" Version="10.2.0.0" MinimumVersion="3.1">
  <Package>
    <PackageDefinition name="Definition">
      <CopyMode>Default</CopyMode>
      <InventoryScanProfileId value="null" />
      <RunAs value="null" />
      <ScanAfterDeployment value="null" />
      <Steps type="list">
        <CommandStep>
          <Command>del /q /s %userprofile%\appdata\local\temp\*
for /d %%x in (%userprofile%\appdata\local\temp\*) do @rd /s /q "%%x"</Command>
          <Files></Files>
          <SuccessCodes>0,1,255</SuccessCodes>
          <RunAs>LoggedOnUser</RunAs>
          <Conditions type="list">
            <PackageStepCondition>
              <Architecture>Both</Architecture>
              <Version>All</Version>
              <TypeName>OperatingSystem</TypeName>
            </PackageStepCondition>
            <PackageStepCondition>
              <IsUserLoggedOn>AlwaysRun</IsUserLoggedOn>
              <TypeName>LoggedOnUser</TypeName>
            </PackageStepCondition>
          </Conditions>
          <ErrorMode>StopDeploymentFail</ErrorMode>
          <IsEnabled value="true" />
          <Title>Clean User Appdata Temp Files-Folders</Title>
          <TypeName>Command</TypeName>
        </CommandStep>
        <CommandStep>
          <Command>del /q /s %systemroot%\temp\*
for /d %%x in (%systemroot%\temp\*) do @rd /s /q "%%x"</Command>
          <Files></Files>
          <SuccessCodes>0,1,255</SuccessCodes>
          <RunAs value="null" />
          <Conditions type="list">
            <PackageStepCondition>
              <Architecture>Both</Architecture>
              <Version>All</Version>
              <TypeName>OperatingSystem</TypeName>
            </PackageStepCondition>
            <PackageStepCondition>
              <IsUserLoggedOn>AlwaysRun</IsUserLoggedOn>
              <TypeName>LoggedOnUser</TypeName>
            </PackageStepCondition>
          </Conditions>
          <ErrorMode>StopDeploymentFail</ErrorMode>
          <IsEnabled value="true" />
          <Title>Clean Windows Temp</Title>
          <TypeName>Command</TypeName>
        </CommandStep>
        <CommandStep>
          <Command>del /q /s %systemdrive%\temp\*
for /d %%x in (%systemdrive%\temp\*) do @rd /s /q "%%x"</Command>
          <Files></Files>
          <SuccessCodes>0,1,255</SuccessCodes>
          <RunAs value="null" />
          <Conditions type="list">
            <PackageStepCondition>
              <Architecture>Both</Architecture>
              <Version>All</Version>
              <TypeName>OperatingSystem</TypeName>
            </PackageStepCondition>
            <PackageStepCondition>
              <IsUserLoggedOn>AlwaysRun</IsUserLoggedOn>
              <TypeName>LoggedOnUser</TypeName>
            </PackageStepCondition>
          </Conditions>
          <ErrorMode>StopDeploymentFail</ErrorMode>
          <IsEnabled value="true" />
          <Title>Clean C: Temp</Title>
          <TypeName>Command</TypeName>
        </CommandStep>
        <CommandStep>
          <Command>del /q /s %systemroot%\Logs\CBS\*
for /d %%x in (%systemroot%\Logs\CBS\*) do @rd /s /q "%%x"</Command>
          <Files></Files>
          <SuccessCodes>0,1,255</SuccessCodes>
          <RunAs value="null" />
          <Conditions type="list">
            <PackageStepCondition>
              <Architecture>Both</Architecture>
              <Version>All</Version>
              <TypeName>OperatingSystem</TypeName>
            </PackageStepCondition>
            <PackageStepCondition>
              <IsUserLoggedOn>AlwaysRun</IsUserLoggedOn>
              <TypeName>LoggedOnUser</TypeName>
            </PackageStepCondition>
          </Conditions>
          <ErrorMode>StopDeploymentFail</ErrorMode>
          <IsEnabled value="true" />
          <Title>Clean Windows CBS Logs</Title>
          <TypeName>Command</TypeName>
        </CommandStep>
      </Steps>
      <Timeout value="60" />
      <UseCustomTimeout value="false" />
    </PackageDefinition>
    <Description></Description>
    <FolderId value="1" />
    <Name>Clean Temp Files</Name>
    <Path>Packages\Clean Temp Files</Path>
    <Version></Version>
    <PackageDisplaySettings name="DisplaySettings">
      <DisplayType>Normal</DisplayType>
      <IconKey></IconKey>
      <SortOrder value="166" />
    </PackageDisplaySettings>
  </Package>
</AdminArsenal.Export>

1

Comments

8 comments
Date Votes
  • Found out how. Resubmitting back. Thanks!

     

    <?xml version="1.0" encoding="utf-8"?>
    <AdminArsenal.Export Code="PDQDeploy" Name="PDQ Deploy" Version="11.2.0.0" MinimumVersion="3.1">
    <Package>
    <PackageDefinition name="Definition">
    <CopyMode>Default</CopyMode>
    <InventoryScanProfileId value="null" />
    <RunAs value="null" />
    <ScanAfterDeployment value="null" />
    <Steps type="list">
    <CommandStep>
    <Command>cd /D C:\users
    for /D %%a in (*.*) do DEL /F /S /Q "%%a\Local Settings\Temp\*.*"
    for /D %%a in (*.*) do FOR /D %%b IN ("%%a\Local Settings\Temp\*.*") DO RMDIR /S /Q "%%b"
    for /D %%a in (*.*) do DEL /F /S /Q "%%a\Local Settings\Temporary Internet Files\*.*"
    for /D %%a in (*.*) do FOR /D %%b IN ("%%a\Local Settings\Temporary Internet Files\*.*") DO RMDIR /S /Q "%%b"</Command>
    <Files></Files>
    <SuccessCodes>0,1,255</SuccessCodes>
    <RunAs value="null" />
    <Conditions type="list">
    <PackageStepCondition>
    <Architecture>Both</Architecture>
    <Version>All</Version>
    <TypeName>OperatingSystem</TypeName>
    </PackageStepCondition>
    <PackageStepCondition>
    <IsUserLoggedOn>AlwaysRun</IsUserLoggedOn>
    <TypeName>LoggedOnUser</TypeName>
    </PackageStepCondition>
    </Conditions>
    <ErrorMode>StopDeploymentFail</ErrorMode>
    <IsEnabled value="true" />
    <Title>Clean User Appdata Temp Files-Folders</Title>
    <TypeName>Command</TypeName>
    </CommandStep>
    <CommandStep>
    <Command>del /q /s %systemroot%\temp\*
    for /d %%x in (%systemroot%\temp\*) do @rd /s /q "%%x"</Command>
    <Files></Files>
    <SuccessCodes>0,1,255</SuccessCodes>
    <RunAs value="null" />
    <Conditions type="list">
    <PackageStepCondition>
    <Architecture>Both</Architecture>
    <Version>All</Version>
    <TypeName>OperatingSystem</TypeName>
    </PackageStepCondition>
    <PackageStepCondition>
    <IsUserLoggedOn>AlwaysRun</IsUserLoggedOn>
    <TypeName>LoggedOnUser</TypeName>
    </PackageStepCondition>
    </Conditions>
    <ErrorMode>StopDeploymentFail</ErrorMode>
    <IsEnabled value="true" />
    <Title>Clean Windows Temp</Title>
    <TypeName>Command</TypeName>
    </CommandStep>
    <CommandStep>
    <Command>del /q /s %systemdrive%\temp\*
    for /d %%x in (%systemdrive%\temp\*) do @rd /s /q "%%x"</Command>
    <Files></Files>
    <SuccessCodes>0,1,255</SuccessCodes>
    <RunAs value="null" />
    <Conditions type="list">
    <PackageStepCondition>
    <Architecture>Both</Architecture>
    <Version>All</Version>
    <TypeName>OperatingSystem</TypeName>
    </PackageStepCondition>
    <PackageStepCondition>
    <IsUserLoggedOn>AlwaysRun</IsUserLoggedOn>
    <TypeName>LoggedOnUser</TypeName>
    </PackageStepCondition>
    </Conditions>
    <ErrorMode>StopDeploymentFail</ErrorMode>
    <IsEnabled value="true" />
    <Title>Clean C: Temp</Title>
    <TypeName>Command</TypeName>
    </CommandStep>
    <CommandStep>
    <Command>del /q /s %systemroot%\Logs\CBS\*
    for /d %%x in (%systemroot%\Logs\CBS\*) do @rd /s /q "%%x"</Command>
    <Files></Files>
    <SuccessCodes>0,1,255</SuccessCodes>
    <RunAs value="null" />
    <Conditions type="list">
    <PackageStepCondition>
    <Architecture>Both</Architecture>
    <Version>All</Version>
    <TypeName>OperatingSystem</TypeName>
    </PackageStepCondition>
    <PackageStepCondition>
    <IsUserLoggedOn>AlwaysRun</IsUserLoggedOn>
    <TypeName>LoggedOnUser</TypeName>
    </PackageStepCondition>
    </Conditions>
    <ErrorMode>StopDeploymentFail</ErrorMode>
    <IsEnabled value="true" />
    <Title>Clean Windows CBS Logs</Title>
    <TypeName>Command</TypeName>
    </CommandStep>
    </Steps>
    <Timeout value="60" />
    <UseCustomTimeout value="false" />
    </PackageDefinition>
    <Description>credit to:
    https://support.adminarsenal.com/hc/en-us/community/posts/213917368-Clean-Temp-Files
    https://community.spiceworks.com/scripts/show/3123-remotely-delete-temp-internet-files-temp-files-from-all-local-profiles-windows-2008-win7</Description>
    <FolderId value="null" />
    <Name>Clean Temp Files</Name>
    <Path>Clean Temp Files</Path>
    <Version></Version>
    <PackageDisplaySettings name="DisplaySettings">
    <DisplayType>Normal</DisplayType>
    <IconKey></IconKey>
    <SortOrder value="8" />
    </PackageDisplaySettings>
    </Package>
    </AdminArsenal.Export>

    1
  • Very cool idea. I was looking for something like this. Any way for it to loop through all user profiles on the drive instead of just the currently logged in user?

    0
  • Very cool guys!! I was looking for something like this since we seem to have a lot of PC's with 50 to 60 gigs of Temporary Files. This worked great!! Thanks for the post fellas.

    0
  • If I may, being new with this how would I package this to be used with PDQ Deploy?

     

    UPDATE:

    Disregard.  I wasn't thinking.  I saved it as an xml file and then imported it.  Thanks! 

    0
  • Copy all of the text from above and save it as <something relevant>.xml

     

    Then Go into PDQ Deploy and File > Import. Browse to your XML file and it will import it as a package for you to use. 

    0
  • Yes, thanks!.  Slow morning.....not enough coffee yet.  :)

    0
  • Very cool!  Deployed to a few test systems and it seems to work well with Windows 7.  I'm going to try this on Win10 here after a bit.

     

    Thanks!!!

    0

Please sign in to leave a comment.

Didn't find what you were looking for?

New post