backup pst files

by Jan 26, 2015

I made script for backup pst file on local disk-second partition in folder backuppst. I copied this script on  three machine and I tryed that start but every time I receive error. My script is

<code>If ((get-process | Where-Object{$_.Name -eq "OUTLOOK"}).Count
-gt 0) 


{
Stop-Process -name "OUTLOOK" -force
}
$today= Get-Date -format "MM-dd-yyyy HH.mm"
$CurrentDate = Get-Date
$days="-1"
$filterlastwritetime=$CurrentDate.AddDays($days)

$drv=Get-WmiObject -class win32_Logicaldisk | Where {
$_.DriveType -eq 3 -and $_.DeviceID -ne 'C:'}
$location= $drv.DeviceID +"backupmail"
$drvpath=$drv.DeviceID+''
$pst=get-childitem "c:", $drvpath -recurse -ErrorAction
SilentlyContinue | where{$_.Path -notlike "*backupmail*" -and
$_.extension -like "*.pst"}
if (!(Test-Path -path $location))
{
md $location
Copy-Item $pst.fullname $location -Force -recurse
cd $location
dir | where-object{$_.LastWriteTime -gt $filterlastwritetime}
| rename-item -newname {$_.name+ ($today)+".pst"}
}
else
{
Copy-Item $pst.fullname $location -Force -Recurse
cd $location
dir | where-object{$_.LastWriteTime -gt $filterlastwritetime}
| rename-item -newname {$_.name+ ($today)+".pst"}
}

$Daysback = "-45"
$DatetoDelete = $CurrentDate.AddDays($Daysback)

Get-ChildItem $location | Where-Object { $_.LastWriteTime -lt
$DatetoDelete } | Remove-Item
</code>

Where is error? Thanks