Solved

Pre-backup command, powershell will not exit from memory after script is finished

Posted on 2015-02-11
4
111 Views
Last Modified: 2015-02-11
Hi,

In my backup program I want to run a pre-backup command that does a backup of my sharepoint site collection. The pre-command runs fine. However, powershell stays in memory after the script is finished.

Because of that, my backup program does not know that it is finished, and will not continue. (If I kill powershell.exe with task manager, the backup continues).

I use the following command: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -NonInteractive -File "C:\backupAllSiteCollections.ps1"

The scipt is this one: https://gallery.technet.microsoft.com/scriptcenter/Backup-all-collections-in-726514cb


If don't want to run the script with the task scheduler (which works fine for the script), because if I use my backup program, I can track errors in the script.

I also have tried as a pre-backup command: schtasks /Run /TN "task name". This does start the task, but does not wait for it to finish.

Does anyone know how I can start the script as a pre-backup command, so that when it is finished, powershell.exe is unloaded from memory (exits)?

Thank you,
Raymond
0
Comment
Question by:Raymond Jansen
  • 2
  • 2
4 Comments
 
LVL 35

Expert Comment

by:Mahesh
ID: 40602678
Try below.
At the end of script type exit on new line

This should force server to close PowerShell from memory and continue backup software
0
 
LVL 7

Author Comment

by:Raymond Jansen
ID: 40602689
Hi,

Does not work unfortunately.

Still in memory. Backup will still not continue.
0
 
LVL 35

Accepted Solution

by:
Mahesh earned 500 total points
ID: 40602772
OK
Try below
at end of script type:
stop-process -Id $PID

This should kill PowerShell process from memory
0
 
LVL 7

Author Closing Comment

by:Raymond Jansen
ID: 40602863
Thanks, works fine like this!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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.
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…

746 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

12 Experts available now in Live!

Get 1:1 Help Now