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

Deploy CMD is complaining the syntax is incorrect but the syntax IS correct

The following 3 lines I can run on cmd shell without issue, I do it all the time, which is why I wanted to PDQ it up.

C:\lgpo.exe /b C:\
FOR /F %i IN ('dir /b {*') DO set lgpodir=%i
C:\LGPO.exe /parse /m C:\%lgpodir%\DomainSysvol\GPO\Machine\registry.pol >> C:\lgpo.txt


But PDQ errors with:

LGPO.exe - Local Group Policy Object Utility
Version 3.0.2004.13001
Copyright (C) 2015-2020 Microsoft Corporation
Security Compliance Toolkit -

Creating LGPO backup in "C:\{31379DC1-DF11-4271-A9DC-16612B190C43}"
The syntax of the command is incorrect.


And specifically I'm pretty sure its upset at this part:

FOR /F %i IN ('dir /b {*') DO set lgpodir=%i


I guess I can't tell it otherwise but how can I get my correct line here to execute from PDQ?




Date Votes
  • Just a bit more info - see how it works manually:


    My command:
    C:\>FOR /F %i IN ('dir /b {*') DO set lgpodir=%i

    Shell replies:
    C:\>set lgpodir={2F335FBA-8D0F-4A23-BAD9-CF2E8ACDE7CE}
  • Deploy executes CMD steps as batch files, so you have to double up the %.

    FOR /F %%i IN ('dir /b {*') DO set lgpodir=%%i
  • OK thanks, it got past the


    FOR /F %%i IN ('dir /b {*') DO set lgpodir=%%i


    but the error is now on the next line. It seems that %lgpodir% isn't set.

    C:\LGPO.exe /parse /m C:\%lgpodir%\DomainSysvol\GPO\Machine\registry.pol >> C:\lgpo.txt
    Cannot open input file "C:\\DomainSysvol\GPO\Machine\registry.pol"


    I tried doing %%lgpodir%% but it just makes:

    Cannot open input file "C:\%lgpodir%\DomainSysvol\GPO\Machine\registry.pol"


    It seems that people do some fancy stuff with batch FOR but I don't see my case...besides why the heck can't it remember my lgopdir var??


  • Deploy does not start in C:\, so you probably need to add the following as the first line:

    CD \
  • Much solve. Very brains