Powershell loop question

Hi,
I am currently running the following powershell command to restore a number of sites.

stsadm -o restore -url http://30242/training/dept11 -filename c:\1\budept.bak -overwrite

I have 11 sites called dept1, dept2, dept3 ... dept11. How do a edit this script to automatically loop thoughand restore all 11 sites instead of running 11 separate commands?

Thanks.
Gary
Grumpy_Old_ManAsked:
Who is Participating?
 
Chris DentConnect With a Mentor PowerShell DeveloperCommented:

I guess the site names aren't just sequential and numeric really?

If they are you could do something like this:

1..11 | ForEach-Object { & { stsadm -o restore -url http://30242/training/dept$_ -filename c:\1\budept.bak -overwrite } }

Otherwise I'm sure there will be way to get the site list dynamically.

Chris
0
 
Grumpy_Old_ManAuthor Commented:
Thanks Chris, that perfect. The sites are sequential, I just have no idea about powershell as yet, but learning :-)

Regards
gary
0
All Courses

From novice to tech pro — start learning today.