?
Solved

powershell command with timer

Posted on 2015-01-30
3
Medium Priority
?
119 Views
Last Modified: 2015-02-02
I have a sequence of events that need to take place for a workstation.

1) it needs to stop the sql service
2) copy mdf and ldf files over the network to a backup location
3) start the sql service

do I have to schedule 3 separate tasks in task scheduler to complete this?

or in one powershell script can I.

1) stop  sxql service
2) wait 30 minutes
3) copy over mdf and ldf files
4) start sql service


or would I have to have 3 separate scripts run each on its own task

task1) stop sql service
task2) copy over folders
task3) start sql service
0
Comment
Question by:jamesmetcalf74
[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
3 Comments
 
LVL 70

Accepted Solution

by:
Qlemo earned 2000 total points
ID: 40579986
Any reason you are not using online backups? MSSQL has pretty easy-to-use commands for that. Putting the instance (!) offline sounds pretty harsh.

But you can do, of course.
stop-service MSSQL$MSSQL2012
start-sleep 30*60
copy-item C:\MsSql\Data\ S:\Backups\ -Include *.ldf, *.mdf, *.ndf
start-service MSSQL$MSSQL2012

Open in new window

MSSQL2012 is the instance name of MSSQL, and the other values should be obvious.
0
 

Author Comment

by:jamesmetcalf74
ID: 40580164
Question Olemo

will step 3 complete before it starts step 4.
will powershell wait until the copy item completes? before it starts step 4

or do i need to put another start-sleep command for a time period that will allow step 3 to complete

Thanks Olemo
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 40580218
A cmdlet always suspends execution until completed, if not used in a pipe (dir | select FullName is a pipe, and will run as whole).
  a
  b
  c
will always execute in sequence, and b only after a has finished, etc.
0

Featured Post

WatchGuard's M Series Appliances - Miecom Approved

WatchGuard's newest M series appliances were put to the test by Miercom.  We had great results and outperformed all of our competitors in both stateless and stateful traffic throghput scenarios! Ready to see how your UTM appliance stacked up? Download the Miercom Report!

Question has a verified solution.

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

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

752 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