1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | function Clear -SCArchive { < # .SYNOPSIS Clears entries from the archive. Defaults to a 30 retention period for the recyclebin. .EXAMPLE Remove all items 30 days or older. PS master:\> Clear -SCArchive .NOTES Michael West michaellwest.blogspot.com @MichaelWest101 about_Comment_Based_Help about_Comparison_Operators about_Functions_Advanced about_Functions_Advanced_Parameters about_Functions_CmdletBindingAttribute #> [CmdletBinding()] param( [ValidateNotNullOrEmpty()] [string] $Name = "recyclebin" , [int] $Days = 30 ) $expired = [datetime]::Now.AddDays(-1 * [Math]::Abs( $Days )) foreach ( $archive in Get -Archive -Name $Name ) { $entries = $archive .GetEntries(0, $archive .GetEntryCount()) foreach ( $entry in $entries ){ if( $entry .ArchiveLocalDate -le $expired ) { Write -Log "Removing item: $($entry.ArchivalId)" $archive .RemoveEntries( $entry .ArchivalId) } else { Write -Verbose "Skipping $($entry.Name) on date $($entry.ArchiveLocalDate)" } } } } |
Saturday, August 24, 2013
Sitecore PowerShell Extensions Creating Functions
Creating a function. Code below.
Labels:
powershell,
sitecore
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment