- /Daily_Backup_review/database_s3_check.ps1 - /Daily_Backup_review/Get-StorageContainerContent.ps1 - /Daily_Backup_review/Global_Checks.ps1 - /Daily_Backup_review/list_table_within_databases.ps1 - /Daily_Backup_review/Start-AzureSQLExport.ps1 - /Daily_Backup_review/Start-BackupCheckBpScus.ps1 - /Daily_Backup_review/Start-BackupCheckBpWeu.ps1 - /Daily_Backup_review/Start-BackupCheckRoserAttachments.ps1 - /Daily_Backup_review/Start-BackupCheckRoserCloud.ps1 - /Daily_Backup_review/Start-BackupCheckTotal.ps1 - /Daily_Backup_review/Start-DatabaseExport.ps1 - /Daily_Backup_review/Start-PointInTimeRestore.ps1 - /Daily_Backup_review/list_databases_within_instances.py - /Daily_Citrix_VDA_and_Server_Utilization_review/Cloudwatch_review/cloudwatch_alarm_ap-southeast-2.json - /Daily_Citrix_VDA_and_Server_Utilization_review/Cloudwatch_review/Cloudwatch_review.ps1 - /Ansible/audit-netscaler-exp.yaml - /Ansible/concurrent-user.yaml - /Ansible/do-something.yaml - /Ansible/hello-world.yaml - /Ansible/p6-log-cleanup.yaml - /Ansible/Roser_DB_backup_one_off.yaml - /Ansible/test-sql.yaml - /Ansible/test-sql-double-creds.yaml - /RoserUsefull/access_bulk_servers.ps1 - /RoserUsefull/access_bulk_servers_cezar.ps1 - /RoserUsefull/Bulk_copy_files.ps1 - /RoserUsefull/Besfort_data.ps1 - /RoserUsefull/check_permissions_bulk_servers.ps1 - /RoserUsefull/Check-p6interface-checksum.ps1 - /RoserUsefull/compare_files.ps1 - /RoserUsefull/connections_parser.ps1 - /RoserUsefull/drop_rds_registry_key.ps1 - /RoserUsefull/EmergencyAccessRemote.ps1 - /RoserUsefull/Keycloak_TestConnection.ps1 - /RoserUsefull/Kickoff_disconnected_users.ps1 - /RoserUsefull/launch_jira.ps1 - /RoserUsefull/launch_jira_gui.ps1 - /RoserUsefull/ownership_taker_anonymized.ps1 - /RoserUsefull/purge_files.ps1 - /RoserUsefull/remove_local_profiles_PowerShell.PS1 - /RoserUsefull/retrieve_attachements.ps1 - /RoserUsefull/Send_patch_multiple_servers.ps1 - /RoserUsefull/Test-RSAAPI-BP.ps1 - /RoserUsefull/Linux_identify_big_files.sh
54 lines
2.4 KiB
PowerShell
54 lines
2.4 KiB
PowerShell
<#
|
|
.Synopsis
|
|
Delete the specific object with the following parameters
|
|
|
|
.Parameter -path
|
|
path of the folder to look for the files ,this is MANDATORY
|
|
|
|
.Parameter -retention_number_of_day
|
|
Value for the number of day the files needs to be older to be deleted, this is MANDATORY
|
|
|
|
.Parameter -pattern_to_delete
|
|
Pattern to target if you need to delete a specific extension or pattern within the filename, this is OPTIONAL
|
|
if you want to specify only the filename put it without any sign
|
|
Example : -pattern_to_delete "catalina"
|
|
|
|
if you want to target extension name specify the dot
|
|
Example : -pattern_to_delete ".log"
|
|
|
|
If you want to specify a specific filename and an extension, just add the * between the word
|
|
Example : -pattern_to_delete "catalina*.log"
|
|
|
|
.Parameter -recurse_boolean
|
|
option to search recursively or not, this is OPTIONAL , DEFAULT = $false
|
|
|
|
.Parameter -dry_run_boolean
|
|
option to perform dry run and display what would be deleted this is OPTIONAL , DEFAULT = $false
|
|
|
|
.Example
|
|
# delete all the log files within the C:\Users\USER\Documents directory for the files older than 30 days with the name log within their name or extension
|
|
deletion_of_specific_objects -path "C:\Users\USER\Documents" -retention_number_of_day 30 -pattern_to_delete "log"
|
|
|
|
# delete all the files within the C:\Users\USER\Documents directory for all the files within all the folder
|
|
deletion_of_specific_objects -path "C:\Users\USER\Documents" -retention_number_of_day 0 -recurse_boolean $true
|
|
|
|
#>
|
|
|
|
function deletion_of_specific_objects{
|
|
param(
|
|
[Parameter (Mandatory = $true)] [String]$path,
|
|
[Parameter (Mandatory = $false)] [String]$pattern_to_delete,
|
|
[Parameter (Mandatory = $true)] [Int]$retention_number_of_day,
|
|
[Parameter (Mandatory = $false)] [boolean]$recurse_boolean = $false,
|
|
[Parameter (Mandatory = $false)] [boolean]$dry_run_boolean = $false
|
|
)
|
|
$recurse_boolean_parameter = @{Recurse = $recurse_boolean}
|
|
$Dry_run = @{Whatif = $dry_run_boolean}
|
|
|
|
Get-ChildItem -Path $path/* -File -Include *$pattern_to_delete* @recurse_boolean_parameter |Where CreationTime -lt (Get-Date).AddDays(-$retention_number_of_day)|Remove-Item @Dry_run
|
|
}
|
|
|
|
|
|
##
|
|
|
|
deletion_of_specific_objects -path "C:\Users\USER\Documents" -retention_number_of_day 30 -pattern_to_delete "*.log" -recurse_boolean $true -dry_run_boolean $false |