Solved

Powershell loop question

Posted on 2010-11-17
2
637 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

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
Make the most of your online learning experience.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

691 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