Solved

powershell command with timer

Posted on 2015-01-30
3
107 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
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 68

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
powershell and sql server - alerting 7 77
Need some help with powershell script 5 37
PowerShell:  Add Header to Out-File 2 28
Powershell Timeout - Exchange 3 11
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

863 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

20 Experts available now in Live!

Get 1:1 Help Now