Windows Disk Cleanup Manager

Octopus.Script exported 2015-10-12 by dbloch belongs to ‘Windows’ category.

Installs Windows Disk Cleanup manager on Windows 2008, 2008-R2 and 2012 Server. Should work on Windows 7 and 8

Parameters

When steps based on the template are included in a project’s deployment process, the parameters below can be set.

Drive Letter

driveLetter = C

The driver letter in which to run the clean up manager on, by default C.

Clean up Level

cleanupSwitch = VERYLOWDISK

2 options are LOWDISK or VERYLOWDISK, varies the level of cleanup that is done. VERYLOWDISK is the most complete, most cleaned up.

Script body

Steps based on this template will execute the following PowerShell script.

$driveLetter = $OctopusParameters["driveLetter"]
$cleanupSwitch = $OctopusParameters["cleanupSwitch"]

#REM  ORIGINAL AUTHOR JAMES FOX 
#REM SOURCE http://technet.microsoft.com/en-us/library/ff630161(WS.10).aspx

#  DECLARATIONS
$SOURCEEXE = ""
$SOURCEMUI = ""
# END DECLARATIONS 

# SETUP TEMPORARY ENVIROMENT VARIABLES FOR COPY PROCESS
$DCLEANMGR = "$env:systemroot\System32"
$DCLEANMGRMUI = "$env:systemroot\System32\en-US"

# $PATH TO MUI FILE          WINDOWS 2008 R2 64bit oR 2012
if (Test-Path $env:systemroot\winsxs\amd64_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.1.7600.16385_en-us_b9cb6194b257cc63\cleanmgr.exe.mui)
{
$SOURCEMUI = "$env:systemroot\winsxs\amd64_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.1.7600.16385_en-us_b9cb6194b257cc63\cleanmgr.exe.mui"
}

# $PATH TO EXE FILE          WINDOWS 2008 R2 64bit oR 2012
if (Test-Path $env:systemroot\winsxs\amd64_microsoft-windows-cleanmgr_31bf3856ad364e35_6.1.7600.16385_none_c9392808773cd7da\cleanmgr.exe)
{
  $SOURCEEXE = "$env:systemroot\winsxs\amd64_microsoft-windows-cleanmgr_31bf3856ad364e35_6.1.7600.16385_none_c9392808773cd7da\cleanmgr.exe"
}


# $PATH TO MUI FILE       WINDOWS 2008 64bit
if (Test-Path $env:systemroot\winsxs\amd64_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.0.6001.18000_en-us_b9f50b71510436f2\cleanmgr.exe.mui)
{
	$SOURCEMUI = "$env:systemroot\winsxs\amd64_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.0.6001.18000_en-us_b9f50b71510436f2\cleanmgr.exe.mui"
}
# $PATH TO EXE FILE       WINDOWS 2008 64bit
if (Test-Path $env:systemroot\winsxs\amd64_microsoft-windows-cleanmgr_31bf3856ad364e35_6.0.6001.18000_none_c962d1e515e94269\cleanmgr.exe)
{
	$SOURCEEXE = "$env:systemroot\winsxs\amd64_microsoft-windows-cleanmgr_31bf3856ad364e35_6.0.6001.18000_none_c962d1e515e94269\cleanmgr.exe"
}

# $PATH TO MUI FILE   WINDOWS 2008 32bit
if (Test-Path $env:systemroot\winsxs\x86_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.0.6001.18000_en-us_5dd66fed98a6c5bc\cleanmgr.exe.mui)
{
	$SOURCEMUI = "$env:systemroot\winsxs\x86_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.0.6001.18000_en-us_5dd66fed98a6c5bc\cleanmgr.exe.mui"
}
# $PATH TO EXE FILE   WINDOWS 2008 32bit
if (Test-Path $env:systemroot\winsxs\x86_microsoft-windows-cleanmgr_31bf3856ad364e35_6.0.6001.18000_none_6d4436615d8bd133\cleanmgr.exe)
{
	$SOURCEEXE = "$env:systemroot\winsxs\x86_microsoft-windows-cleanmgr_31bf3856ad364e35_6.0.6001.18000_none_6d4436615d8bd133\cleanmgr.exe"
}

# COPY PROCESS 
# THIS SECTION SHOULD NEVER HAPPEN ON WINDOWS 2003 SERVER BECAUSE CLEANMGR.EXE IS ALWAYS INSTALLED
# TEST AND COPY IF CLEANMGR.EXE DOES NOT EXIST IN EXPECTED LOCATION COPY FROM SOURCE EXE AND MUI
if (!(Test-Path $env:systemroot\SYSTEM32\cleanmgr.exe))
{
  xcopy $SOURCEMUI $DCLEANMGRMUI /y
}
if (!(Test-Path $env:systemroot\SYSTEM32\cleanmgr.exe))
{
  xcopy $SOURCEEXE $DCLEANMGR /y
}

# RUN EXE AND CLEAN DRIVE MAX CLEANUP
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
$pinfo.FileName = "$env:systemroot\SYSTEM32\CLEANMGR.EXE"
$pinfo.RedirectStandardError = $true
$pinfo.RedirectStandardOutput = $true
$pinfo.UseShellExecute = $false
$pinfo.Arguments = "/d$driveLetter /$cleanupSwitch"
$p = New-Object System.Diagnostics.Process
$p.StartInfo = $pinfo
$p.Start() | Out-Null
$p.WaitForExit()
$stdout = $p.StandardOutput.ReadToEnd()
$stderr = $p.StandardError.ReadToEnd()
Write-Host "stdout: $stdout"
Write-Host "stderr: $stderr"
Write-Host "Exit Code: " + $p.ExitCode

Provided under the Apache License version 2.0.

Report an issue

To use this template in Octopus Deploy, copy the JSON below and paste it into the Library → Step templates → Import dialog.

{
  "Id": "0147e912-ff8d-46d9-965a-dee0789ef32b",
  "Name": "Windows Disk Cleanup Manager",
  "Description": "Installs Windows Disk Cleanup manager on Windows 2008, 2008-R2 and 2012 Server.  Should work on Windows 7 and 8",
  "Version": 4,
  "ExportedAt": "2015-10-12T19:07:41.676+00:00",
  "ActionType": "Octopus.Script",
  "Author": "dbloch",
  "Parameters": [
    {
      "Name": "driveLetter",
      "Label": "Drive Letter",
      "HelpText": "The driver letter in which to run the clean up manager on, by default C.",
      "DefaultValue": "C",
      "DisplaySettings": {
        "Octopus.ControlType": "Select",
        "Octopus.SelectOptions": "C\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nO\nP\nQ\nR\nS\nT\nU\nV\nW\nX\nY\nZ"
      }
    },
    {
      "Name": "cleanupSwitch",
      "Label": "Clean up Level",
      "HelpText": "2 options are LOWDISK or VERYLOWDISK, varies the level of cleanup that is done.  VERYLOWDISK is the most complete, most cleaned up.",
      "DefaultValue": "VERYLOWDISK",
      "DisplaySettings": {
        "Octopus.ControlType": "Select",
        "Octopus.SelectOptions": "VERYLOWDISK| Very Low Disk\nLOWDISK\\Low Disk"
      }
    }
  ],
  "Properties": {
    "Octopus.Action.Script.Syntax": "PowerShell",
    "Octopus.Action.Script.ScriptBody": "$driveLetter = $OctopusParameters[\"driveLetter\"]\n$cleanupSwitch = $OctopusParameters[\"cleanupSwitch\"]\n\n#REM  ORIGINAL AUTHOR JAMES FOX \n#REM SOURCE http://technet.microsoft.com/en-us/library/ff630161(WS.10).aspx\n\n#  DECLARATIONS\n$SOURCEEXE = \"\"\n$SOURCEMUI = \"\"\n# END DECLARATIONS \n\n# SETUP TEMPORARY ENVIROMENT VARIABLES FOR COPY PROCESS\n$DCLEANMGR = \"$env:systemroot\\System32\"\n$DCLEANMGRMUI = \"$env:systemroot\\System32\\en-US\"\n\n# $PATH TO MUI FILE          WINDOWS 2008 R2 64bit oR 2012\nif (Test-Path $env:systemroot\\winsxs\\amd64_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.1.7600.16385_en-us_b9cb6194b257cc63\\cleanmgr.exe.mui)\n{\n$SOURCEMUI = \"$env:systemroot\\winsxs\\amd64_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.1.7600.16385_en-us_b9cb6194b257cc63\\cleanmgr.exe.mui\"\n}\n\n# $PATH TO EXE FILE          WINDOWS 2008 R2 64bit oR 2012\nif (Test-Path $env:systemroot\\winsxs\\amd64_microsoft-windows-cleanmgr_31bf3856ad364e35_6.1.7600.16385_none_c9392808773cd7da\\cleanmgr.exe)\n{\n  $SOURCEEXE = \"$env:systemroot\\winsxs\\amd64_microsoft-windows-cleanmgr_31bf3856ad364e35_6.1.7600.16385_none_c9392808773cd7da\\cleanmgr.exe\"\n}\n\n\n# $PATH TO MUI FILE       WINDOWS 2008 64bit\nif (Test-Path $env:systemroot\\winsxs\\amd64_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.0.6001.18000_en-us_b9f50b71510436f2\\cleanmgr.exe.mui)\n{\n\t$SOURCEMUI = \"$env:systemroot\\winsxs\\amd64_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.0.6001.18000_en-us_b9f50b71510436f2\\cleanmgr.exe.mui\"\n}\n# $PATH TO EXE FILE       WINDOWS 2008 64bit\nif (Test-Path $env:systemroot\\winsxs\\amd64_microsoft-windows-cleanmgr_31bf3856ad364e35_6.0.6001.18000_none_c962d1e515e94269\\cleanmgr.exe)\n{\n\t$SOURCEEXE = \"$env:systemroot\\winsxs\\amd64_microsoft-windows-cleanmgr_31bf3856ad364e35_6.0.6001.18000_none_c962d1e515e94269\\cleanmgr.exe\"\n}\n\n# $PATH TO MUI FILE   WINDOWS 2008 32bit\nif (Test-Path $env:systemroot\\winsxs\\x86_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.0.6001.18000_en-us_5dd66fed98a6c5bc\\cleanmgr.exe.mui)\n{\n\t$SOURCEMUI = \"$env:systemroot\\winsxs\\x86_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.0.6001.18000_en-us_5dd66fed98a6c5bc\\cleanmgr.exe.mui\"\n}\n# $PATH TO EXE FILE   WINDOWS 2008 32bit\nif (Test-Path $env:systemroot\\winsxs\\x86_microsoft-windows-cleanmgr_31bf3856ad364e35_6.0.6001.18000_none_6d4436615d8bd133\\cleanmgr.exe)\n{\n\t$SOURCEEXE = \"$env:systemroot\\winsxs\\x86_microsoft-windows-cleanmgr_31bf3856ad364e35_6.0.6001.18000_none_6d4436615d8bd133\\cleanmgr.exe\"\n}\n\n# COPY PROCESS \n# THIS SECTION SHOULD NEVER HAPPEN ON WINDOWS 2003 SERVER BECAUSE CLEANMGR.EXE IS ALWAYS INSTALLED\n# TEST AND COPY IF CLEANMGR.EXE DOES NOT EXIST IN EXPECTED LOCATION COPY FROM SOURCE EXE AND MUI\nif (!(Test-Path $env:systemroot\\SYSTEM32\\cleanmgr.exe))\n{\n  xcopy $SOURCEMUI $DCLEANMGRMUI /y\n}\nif (!(Test-Path $env:systemroot\\SYSTEM32\\cleanmgr.exe))\n{\n  xcopy $SOURCEEXE $DCLEANMGR /y\n}\n\n# RUN EXE AND CLEAN DRIVE MAX CLEANUP\n$pinfo = New-Object System.Diagnostics.ProcessStartInfo\n$pinfo.FileName = \"$env:systemroot\\SYSTEM32\\CLEANMGR.EXE\"\n$pinfo.RedirectStandardError = $true\n$pinfo.RedirectStandardOutput = $true\n$pinfo.UseShellExecute = $false\n$pinfo.Arguments = \"/d$driveLetter /$cleanupSwitch\"\n$p = New-Object System.Diagnostics.Process\n$p.StartInfo = $pinfo\n$p.Start() | Out-Null\n$p.WaitForExit()\n$stdout = $p.StandardOutput.ReadToEnd()\n$stderr = $p.StandardError.ReadToEnd()\nWrite-Host \"stdout: $stdout\"\nWrite-Host \"stderr: $stderr\"\nWrite-Host \"Exit Code: \" + $p.ExitCode\n"
  },
  "Category": "Windows",
  "HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/windows-disk-cleanup.json",
  "Website": "/step-templates/0147e912-ff8d-46d9-965a-dee0789ef32b",
  "Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADNQTFRF////Da3qSsLvhtb0wur6O7zuWcfxldv2aMzyK7ftpOD3s+X48Pr+0fD7d9HzHLLr4fX8xD/OcwAAAaNJREFUeNrs3cFygjAUQFECWott1f//2sJoW6kIKEzNs+euXOmcmSSGDa8oJEmSJEmSJGmsj1W1K9cpsGD1Vr2WdToVEPC+2lYvZfpVrEW0qZpF1F+MRdRugzoNlvkiarfBPk0pT8GhWUSX2yASpDlLr2+DEJBmEY1ug6whx7N0n2b30G1QlmmxHsRYp6X76yvF9vg5RYQczq8UVURI35UiFmTgShED0p6lI1eKzCHTrxS5Qk6PZ9PLDtJ9PIsJmXWlyAky6/dAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQMJCyjltF/iO3gpJUpD8s4OAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgID8T8itwwKyhbTdMr4ha8hXUwZqhICcOgyNOIkE+V5wo4MSgr1u/fp7poO+AL8K/gL8yw0UeyRB34m9iQ/pVD8L5JYTO3NI58R+AsiEEzsW5OfE3sUe/zRwYkeGnG2g2CPS7rhjF4GKP0ZwyoldxK37kFqEL/7wU0mSJEmSJOmJ+xRgAHxZTCXGdZkfAAAAAElFTkSuQmCC",
  "$Meta": {
    "Type": "ActionTemplate"
  }
}

History

Page updated on Monday, October 12, 2015