Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

When I load this command IN powershell ISE

Status
Not open for further replies.

VESTERMARTIN2008

IS-IT--Management
Apr 17, 2017
2
US
When I load this command I get the error at the bottom.

PS C:\WINDOWS\system32> $intFolders = 10
$intPad
$i = 1
New-Variable -Name strPrefix -Value "testFolder" -Option constant
do {
if ($i -lt 10)
{$intPad=0
New-Item -Path C:\mytempFolder -Name $strPrefix$intPad$i -Type directory}
else

I get this error message when I load this command above. please help I ma really new to all this


Missing statement block after 'else' keyword.
+ CategoryInfo : ParserError: :)) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingStatementBlockAfterElse
 
You don't have to have an else clause. However, if you do you must include the braces.

Code:
## Example 1
if (condition)
[indent]{code to run}[/indent]


## Example 2
if (condition)
[indent]{code to run}[/indent]
else
[indent]{alternate code to run}[/indent]


## To fix your code
if ($i -lt 10)
{$intPad=0
New-Item -Path C:\mytempFolder -Name $strPrefix$intPad$i -Type directory}
else
[COLOR=#EF2929][b]{}[/b][/color]


Light travels faster than sound. That's why some people appear bright until you hear them speak.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top