0

I want to use PowerShell script which delete old Backup Files in SharePoint2010 Backup Folder. I've found this script:

# Location of spbrtoc.xml
$spbrtoc = "\\XXX\spbrtoc.xml" 

# Days of backup that will be remaining after backup cleanup.
$days = 7 

# Import the Sharepoint backup report xml file
[xml]$sp = gc $spbrtoc 

# Find the old backups in spbrtoc.xml
$old = $sp.SPBackupRestoreHistory.SPHistoryObject |
? { $_.SPStartTime -lt ((get-date).adddays(-$days)) }
if ($old -eq $Null) { write-host "No reports of backups older than $days days found in spbrtoc.xml.`nspbrtoc.xml isn't changed and no files are removed.`n" ; break} 

# Delete the old backups from the Sharepoint backup report xml file
$old | % { $sp.SPBackupRestoreHistory.RemoveChild($_) } 

# Delete the physical folders in which the old backups were located
$old | % { Remove-Item $_.SPBackupDirectory -Recurse } 

# Save the new Sharepoint backup report xml file
$sp.Save($spbrtoc)
Write-host "Backup(s) entries older than $days days are removed from spbrtoc.xml and harddisc."

but I get 2 errors back:

Exception calling "RemoveChild" with "1" argument(s): "Object reference not set to an instance of an object." At line:1 char:50 + $old | % { $sp.SPBackupRestoreHistory.RemoveChild <<<< ($_) } + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException

Remove-Item : Cannot bind argument to parameter 'Path' because it is null. At line:1 char:23 + $old | % { Remove-Item <<<< $_.SPBackupDirectory -Recurse } + CategoryInfo : InvalidData: (:) [Remove-Item], ParameterBinding ValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,M
icrosoft.PowerShell.Commands.RemoveItemCommand

  • Looks like script did not find the spbrtoc.xml file....are you sure you give the correct path of the file and correct filename? – Waqas Sarwar MVP Oct 30 '15 at 2:24
  • remember to use sp mgmnt shell as a admin too – Michał Dem Oct 30 '15 at 10:33
  • It could save the new spbrtoc.xml file but it couldn't delete the old folders – Melika Oct 30 '15 at 18:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.