Solved

Powershell Error: missing statement body in for loop

Posted on 2013-06-07
2
822 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 84

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

When you try to extract and to view the contents of a Microsoft Update Standalone Package (MSU) for Windows Vista, you cannot extract the files from the MSU. Here we are going to explain how to extract those hotfix details without using any third pa…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.

751 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