Solved

powershell command with timer

Posted on 2015-01-30
3
106 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
  • 2
3 Comments
 
LVL 68

Accepted Solution

by:
Qlemo earned 500 total points
Comment Utility
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
Comment Utility
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 68

Expert Comment

by:Qlemo
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Hi all.   The other day I had to change the passwords for a bunch of users on the fly. Because they were so many, I decided to do it in an automated way and I would like to share it with you all.   If you are not doing it directly in a Domain Co…
Set OWA language and time zone in Exchange for individuals, all users or per database.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

771 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now