?
Solved

powershell command with timer

Posted on 2015-01-30
3
Medium Priority
?
120 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 71

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 71

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

649 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