lundi 20 avril 2015

Create number of folders in Powershell Script

The script needs to read the argument and if it is greater than 15 exit or less than 1 exit. Having troubles with the "IF" Statements. Keeps giving me Missing Parenthesis errors.

$Input = Read-Host 'How many folders would you like to create?' 
$Input
If
{
($Input -gt 15) then
echo "Error too many arguments"
End If
}
{
else ($Input -lt 1) then
echo "Error: Not enough arguements"
End If
}
$intFolders = $Input
$intPad
$i = 1
New-Variable =Name striPrefix -Value "testFolder" -Option constant
do {
if ($i -lt 10)
{$intPad = 0
New-Item -path c:\mytest -name $strPrefix$intPad$i -type directory}
else
{New-Item -path c:\mytest -name $strPrefix$i -type directory}
$i++
}until ($i -eq $intFolders+1)

Aucun commentaire:

Enregistrer un commentaire