Monday, December 20, 2010

Creating Scheduled Task via GPO fails on Windows Server 2008 or Vista

When creating a Scheduled Task via GPO and applying it on Windows Server 2008 (or Windows Vista), the task will not appear in Administrative Tools -> Task Scheduler on the affected machines. Instead, the following error appears in the Event Log:

The computer 'Compress Logs and Backups' preference item in the 'Scheduled Tasks - Compress Logs and Backups {A76A14CE-5000-4AD7-931C-81D50A768C29}' Group Policy object did not apply because it failed with error code '0x80070057 The parameter is incorrect.' This error was suppressed.

The error is pretty lame, actually a missing 'Start in' parameter in the GPO.


After filling in the Start in: parameter with any value, and doing a gpupdate, the scheduled task suddenly appeared on the servers where the GPO is applied. Yaay :D

Friday, December 10, 2010

7-zip compress full paths from directory listing

7-zip is an excellent free tool for file compression, but it lacks a feature that is very annoying. 

This is preserving the absolute path of the files in an archive. When adding multiple files one-by-one, eg. with a batch script, this can cause lots of headaches. The same happened to me, until I wrapped up this little batch script that will CROP down the trailing drive letters from a directory listing. In this example I will list files that have been changed since a specific date but a dir /s /b > filelist.txt will also do the job (look out for the correct quotation marks that might differ between forfiles and dir)

@echo off
REM -- you need this for dynamic variables
setlocal ENABLEDELAYEDEXPANSION
REM -- date since files have changed
set Since=11/25/2010
REM -- root path for the data being archived as well as for the 7z file in this case
set MyAppPath=C:\Inetpub\wwwroot\PDF
REM -- change active directory to root so 7z will like the listing
cd /d C:\
REM -- generate file list
Forfiles -p %MyAppPath% /s /m *.* /D %Since% /C "cmd /C echo @path>>%MyAppPath%\filelist.txt"
REM -- take all lines from filelist.txt, crop down the trailing drive letter and add a " in front
REM -- then execute 7z with the result; 7z will use store compression in this case.
for /f "tokens=* delims= " %%a in (%MyAppPath%\filelist.txt) do (
 set PDFPath=%%a
 "c:\program files\7-zip\7z.exe" a -t7z -mx0 %MyAppPath%\archive.7z ^"!PDFPath:~4,-1!
)
del filelist.txt



And that's it :)