Solved

powershell command with timer

Posted on 2015-01-30
3
115 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 500 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

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

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

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
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, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

705 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