Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Powershell loop question

Posted on 2010-11-17
2
Medium Priority
?
639 Views
Last Modified: 2012-05-10
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
0
Comment
Question by:Grumpy_Old_Man
2 Comments
 
LVL 71

Accepted Solution

by:
Chris Dent earned 1000 total points
ID: 34153775

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
 

Author Closing Comment

by:Grumpy_Old_Man
ID: 34153831
Thanks Chris, that perfect. The sites are sequential, I just have no idea about powershell as yet, but learning :-)

Regards
gary
0

Featured Post

Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Question has a verified solution.

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

In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

773 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