Solved

Powershell Error: missing statement body in for loop

Posted on 2013-06-07
2
756 Views
Last Modified: 2013-06-07
When running the follow script I get an error as follows, any suggestions:

At C:\Users\eroche\desktop\prod2testcopy.ps1:4 char:109
+ ... NewestFile=%%I)
+                    ~
Missing statement body in for loop.
    + CategoryInfo          : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : MissingLoopStatement


The Script:

SET DatabaseBackupPath=\\fpbackup\backup
echo.
echo Restore Database
FOR (/F "delims=|" %%I IN ('DIR "%DatabaseBackupPath%\sql\AOSProd_backup*.bak" /B /O:D') set NewestFile=%%I)
copy "%DatabaseBackupPath%\WebServer\%NewestFile%" "c:\"
0
Comment
Question by:FennerIT
2 Comments
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 39230141
That is not a Powershell script, it's a batch script. Save it as prod2testcopy.cmd and try again.
SET DatabaseBackupPath=\\fpbackup\backup
echo.
echo Restore Database
FOR /F "delims=" %%I IN ('DIR "%DatabaseBackupPath%\sql\AOSProd_backup*.bak" /B /O:D') set NewestFile=%%I
copy "%DatabaseBackupPath%\WebServer\%NewestFile%" "c:\"

Open in new window

0
 

Author Comment

by:FennerIT
ID: 39230218
Opps thought it was a Powershell script the way the article read. Thanks.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
On some Windows 7 (SP1) computers, Windows Update becomes super slow even the computer is reasonably fast.  There's one solution that seemed to have worked well for me (after trying a few other suggested solutions).
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
In this Micro Tutorial viewers will learn how to use Boot Corrector from Paragon Rescue Kit Free to identify and fix the boot problems of Windows 7/8/2012R2 etc. As an example is used Windows 2012R2 which lost its active partition flag (often happen…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now