我已經been using this()腳本刪除較舊的共享點備份,但它會刪除所有備份而不是14天以上的備份。如何更正此PowerShell腳本自動刪除Sharepoint備份
我通過powershell_ise.exe運行它,並在其中包含$_.SPStartTime
的行下放置一個斷點,並且它顯示$_.SPStartTime =
就好像日期未填充一樣。我看着裏面的$sp.SPBackupRestoreHistory.SPHistoryObject
,包含我期望的數據。
這是有問題的部分是在這條線:
# Find the old backups in spbrtoc.xml
$old = $sp.SPBackupRestoreHistory.SPHistoryObject |
? { $_.SPStartTime -lt ((get-date).adddays(-$days)) }
我得到的所有的日期輸出(這是我所期望的)的。這告訴我在'哪裏'或'?'的問題 - 我知道它們是可以互換的。無論如何,$ old總是顯示爲空。
的要求:
<?xml version="1.0" encoding="utf-8"?>
<SPBackupRestoreHistory>
<SPHistoryObject>
<SPId>a8a03c50-6bc2-4af4-87b3-caf60e750fa0</SPId>
<SPRequestedBy>ASERVER\AUSER</SPRequestedBy>
<SPBackupMethod>Full</SPBackupMethod>
<SPRestoreMethod>None</SPRestoreMethod>
<SPStartTime>01/09/2011 00:00:13</SPStartTime>
<SPFinishTime>01/09/2011 00:05:22</SPFinishTime>
<SPIsBackup>True</SPIsBackup>
<SPConfigurationOnly>False</SPConfigurationOnly>
<SPBackupDirectory>E:\Backups\spbr0003\</SPBackupDirectory>
<SPDirectoryName>spbr0003</SPDirectoryName>
<SPDirectoryNumber>3</SPDirectoryNumber>
<SPTopComponent>Farm</SPTopComponent>
<SPTopComponentId>689d7f0b-4f64-45d4-ac58-7ab225223625</SPTopComponentId>
<SPWarningCount>0</SPWarningCount>
<SPErrorCount>0</SPErrorCount>
</SPHistoryObject>
<SPHistoryObject>
<SPId>22dace04-c300-41d0-a9f1-7cfe638809ef</SPId>
<SPRequestedBy>ASERVER\AUSER</SPRequestedBy>
<SPBackupMethod>Full</SPBackupMethod>
<SPRestoreMethod>None</SPRestoreMethod>
<SPStartTime>01/08/2011 00:00:13</SPStartTime>
<SPFinishTime>01/08/2011 00:05:26</SPFinishTime>
<SPIsBackup>True</SPIsBackup>
<SPConfigurationOnly>False</SPConfigurationOnly>
<SPBackupDirectory>E:\Backups\spbr0002\</SPBackupDirectory>
<SPDirectoryName>spbr0002</SPDirectoryName>
<SPDirectoryNumber>2</SPDirectoryNumber>
<SPTopComponent>Farm</SPTopComponent>
<SPTopComponentId>689d7f0b-4f64-45d4-ac58-7ab225223625</SPTopComponentId>
<SPWarningCount>0</SPWarningCount>
<SPErrorCount>0</SPErrorCount>
</SPHistoryObject>
</SPBackupRestoreHistory>
我會看看這個,但你的說法是有道理的......驚訝沒有人注意到這一點在他們的博客。 – 2011-01-10 11:42:14
查看更新後的問題 - 我認爲問題出在過濾,因爲$ old始終爲空 – 2011-01-10 12:31:31