Friday 14 December 2012

Delete Temp internet and other files from XP Desktop - Batch Script

rem @ECHO OFF
SET SRC1=C:\Documents and Settings
SET SRC2=Local Settings\Temporary Internet Files\
SET SRC3=Local Settings\History
SET SRC4=Local Settings\Temp
SET SRC5=Recent
echo About to delete files from Internet Explorer "Temporary Internet files"
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC2%\*.*") DO RMDIR /S /Q "%%Y"
echo About to delete files from Internet Explorer "History"
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC3%\*.*") DO RMDIR /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC3%\*.*") DO DEL /F /S /Q "%%Y"
echo About to delete files from "Local settings\temp"
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC4%\*.*") DO RMDIR /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC4%\*.*") DO DEL /F /S /Q "%%Y"
echo About to delete files from "Recent" i.e. what appears in Start/Documents/My Documents
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC5%\*.lnk") DO DEL /F /S /Q "%%Y"
echo About to delete files from "Windows\Temp"
cd /d %SystemRoot%\temp
del /F /Q *.*
@echo Y|RD /S ""

Get disk space with Powershell

$computername='MyComputerName'

Get-WmiObject win32_logicaldisk -ComputerName $computername -Filter {freespace>0} | Format-Table @{l='Computername';e={$computername}},@{l='Drive';e={$_.DeviceID}},@{l='Size';e={(($_.Size/1024)/1024)/1024}}, @{l='FreeSpace';e={(($_.FreeSpace/1024)/1024)/1024}}

Thursday 13 December 2012

Uninstall Windows Patches with Batch Script




Example of Script

for /f "eol=; tokens=1" %%i in (C:\KBNames.txt) do call :PROCESS %%i

goto :EOF

:PROCESS
set KB=%*
start /wait %windir%\$NtUninstall%KB%$\spuninst\spuninst.exe /quiet /norestart
:Exit


Example of KBNames.txt

KB1234567
KB2345678
KB1234567
KB2345678
KB1234567
KB2345678