[CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [URI]$uri, # Delete snapshots after the specified days. [Parameter(Mandatory = $true)] [int]$removeOlderThan = 100, [Parameter()] [string]$username = "", [Parameter()] [string]$password = "" ) # Set credentials if ($username -eq "") { $credentials = Get-Credential } else { $credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username, (ConvertTo-SecureString -String $password -AsPlainText -Force) } # Connect to Liquit. $context = Connect-LiquitWorkspace -URI $uri -Credential $credentials; # Get all packages. $packages = Get-LiquitPackage; # Remove after x number of days. $removeAfter = [DateTime]::Today.AddDays(-$removeOlderThan); # Loop through the packages. foreach ($package in $packages) { # Get all snapshots. $snapshots = $package | Get-LiquitPackageSnapshot # Loop through the snapshots. foreach ($snapshot in $snapshots) { # Skip active snapshots and sandboxes. if (($snapshot.Type -eq "Development") -or ($snapshot.Type -eq "Test") -or ($snapshot.Type -eq "Acceptance") -or ($snapshot.Type -eq "Production")) { continue; } # Verify age. if ($removeAfter -le $snapshot.CreatedAt) { continue; } Write-Host "Removing snapshot on package ""$($package.Name)"" with name ""$($snapshot.Name)""." try { # Remove snapshot. $snapshot | Remove-LiquitPackageSnapshot } catch { if (($_.Exception).Code -eq "Authorization_RequestDenied"){ Write-Host "Insufficient privileges to delete the snapshot on package " "$($package.Name)"" with name ""$($snapshot.Name)""." } } } }