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 - https://www.microsoft.com/download/details.aspx?id=55319

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?

 

0

Comments

5 comments
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}
    0
  • Deploy executes CMD steps as batch files, so you have to double up the %.

    https://ss64.com/nt/for.html

    FOR /F %%i IN ('dir /b {*') DO set lgpodir=%%i
    1
  • 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??

     

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

    CD \
    1
  • Much solve. Very brains

    0

Please sign in to leave a comment.

Didn't find what you were looking for?

New post