PowerShell Backup with Copy-Item

PowerShell Script to Backup Outlook.pst

Here is a PowerShell script that will backup your Outlook.pst email file.  While there is no backup verb in PowerShell, you can get the job done with the Copy-Item cmdlet.

Topics for PowerShell Backup

 ♣

Copy-Item Parameters -Path and -Destination

As with all backups, Copy-Item needs is the source (-path) and the destination for the copied file(s).

Outlook File(s)
In this example the source file will be outlook.pst (Personal Storage File).  To check the whereabouts of your .pst file, open Outlook, click on File Menu and then open Account settings. Observe the path to the email account that you wish to backup.

PowerShell Script
I like to create a special folder to hold all my PowerShell .ps1 files.  You will need this path if you are going to employ Task Scheduler to action the script.

The Backup File Itself
In the script below, Copy-Item delivers the backup to a folder on my D:\drive. 

# PowerShell script to backup your email
$Outlook ="C:\Users\person*\AppData\Local\Microsoft\Outlook\outlook.pst
$PstDest ="D:\Backup\Person"
Copy-Item -Path $Outlook -Destination $PstDest
Get-ChildItem $PstDest

Note 1*: Amend C:\Users\Person

Note 2: To prepare for the scheduled task, save your script with a name such as: C: \Scripts\OutlookPerson.ps1.

Note 3: When I use this technique for real I prefer to backup to a different machine.  What I do is share out the Outlook folder, and then master the \\server\share syntax.

Kiwe CatTools - Free downloadGuy’s Challenge – Download this free device backup utility

(CatTools)

Kiwi CatTools is a free program for backing up configuration settings on hardware devices.  Here is Guy’s challenge.  If you download CatTools, then it will not only take care of backups, but also it will show you something new about the hardware on you network. I could give you a money back guarantee – but CatTools is already free!  Thus, I just make a techie to techie challenge, you will learn more about your network if you:

Download your free Kiwi CatTools configuration backup tools

PowerShell Backup with Task Scheduler

Backups are best run on a schedule, and for that I prefer to employ a the dedicated Windows Task Scheduler service.PowerShell Backup Copy-Item

Launch the Built-In Windows Task Scheduler.  Select ‘Create a task’ (I don’t like the Basic task), enter a suitable name such as OutlookBackup

Trigger (Tab): Decide when to run the PowerShell script, for example when it’s idle at lunch time.

Actions (Tab): Type PowerShell in the Program/script box: [Key point].

You put the name of the script containing the Copy-Item instructions in the ‘Add arguments’ box underneath.  See screenshot to the right.

Conditions (Tab): Because this file copying slows down the machine, I put a tick next to ‘Stop if the computer ceases to be idle’.

Settings (Tab). I like to tick the box saying: Run task as soon as possible after a schedule is missed.

See more on Task Scheduler »

Troubleshooting Your Copy-Item Backup

Problem 1: You put the name of the script in the Program/script box; what happens is that notepad launches the script – Wrong.  Instead, just type the name ‘PowerShell’ in the Program/script box. 

Problem 2: If you have spaces in the file name, then enclosed the whole path with double quote speech marks

 -File "C:\Scripts\Outlook Backup.ps1"

Problem 3: -ExecutionPolicy Bypass will ensure that the PowerShell scheduled task will run even thought the computer has a restricted script policy.  However, there is a secret, and that is to ensure this parameter is at the beginning of the arguments thus:
-ExecutionPolicy Bypass -File "C:\Scripts\Outlook Backup.ps1"

Guy Recommends:  A Free Trial of the Network Performance Monitor (NPM)Review of Orion NPM v11.5 v11.5

SolarWinds’ Network Performance Monitor will help you discover what’s happening on your network.  This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.

What I like best is the way NPM suggests solutions to network problems.  Its also has the ability to monitor the health of individual VMware virtual machines.  If you are interested in troubleshooting, and creating network maps, then I recommend that you try NPM now.

Download a free trial of Solarwinds’ Network Performance Monitor

Register-ScheduledTask

While I prefer to use WindowsTask Scheduler, others prefer to employ PowerShell’s native function (cmdlet): Register-ScheduledTask

Register-ScheduledTask -TaskName $GuyTask `
-TaskPath "C:\Scripts\Outlook Backup.ps1" `
-Action $Action `
-Trigger $Trigger
-Settings $Settings

Parameters for PowerShell’s Copy-Item

Call for help and research Copy-Item’s parameters.

Clear-Host
Get-Help Copy-Item -Full

 

Note 4: The -Recurse parameter is interesting, it specifies whether you want a copy of the original folder name.  Try this experiment with and without -Recurse.

Clear-Host
$Path = "D:\PShell\VBScript\*"
$Dest = "H:\Expt"
Copy-Item $Path $Dest #-Recurse
Get-ChildItem $Dest -Recurse

See more tasks for PowerShell and Outlook ยป

Summary of PowerShell Backup

Firstly, realise that PowerShell has no Backup cmdlet, instead you need Copy-Item.  Secondly, pay close attention to the locations of the relevant files.  The original email .pst file, the path to the copy, and where you store the PowerShell script.

If you like this page then please share it with your friends

 


See more Microsoft PowerShell file tutorials:

PowerShell Home    • PowerShell Backup Copy-Item   • PowerShell Files  • Free Import CSVDE Tool

PowerShell Registry  • Get-Credential  • PowerShell ItemProperty   • PowerShell -Recurse

PowerShell Get-ChildItem  • PowerShell -Filter   • Free Permissions AnalyzerCompare-Object

Please email me if you have a better example script. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.