Solved

Powershell loop question

Posted on 2010-11-17
2
636 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
[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 71

Accepted Solution

by:
Chris Dent earned 250 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

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

Suggested Solutions

Title # Comments Views Activity
sharepoint 2013 foundation 2 28
PowerShell and cisco ios 3 46
export the mailbox data to .pst from office365 mailbox 8 54
Sharepoint list to Access database 9 51
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
In case you ever have to remove a faulty web part from a page , add the following to the end of the page url ?contents=1
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 antispam), the admini…

726 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