Deleting Files based on Retention Period

This topic contains 2 replies, has 3 voices, and was last updated by  postanote 4 months ago.

  • Author
    Posts
  • #91771

    nottyheadedboss
    Participant

    Hi,

    I would like some assistance to start buidling a script to delete files from specific folders based on the retention periods mentioned in the configuration file
    config.xml

     [Config]
      [Retention]
        [Drive1]
          [Path]E:\PowerShell\1\Reports\Fiction\Archive[/Path]
          [Days]90[/Days]
        [/Drive1]
        [Drive2]
          [Path]E:\PowerShell\2\Reports\NonFiction\Archive[/Path]
          [Days]7[/Days]
        [/Drive2]
        [Drive3]
          [Path]E:\PowerShell\3\Reports\Bios\Archive[/Path]
          [Days]7[/Days]
        [/Drive3]
      [/Retention]
    [/Config]
    

    The script should be able to read the data from the Config file and delete all files in the folder that are equal to or greater than the time period mentioned in the tag.

    Thanks

  • #91778

    Sam Boutros
    Participant

    Please share the code you've written so far.

  • #91843

    postanote
    Participant

    All you need to get you going down the right direction is in the PowerShell built-in Help files...

    Get parameter, examples, full and Online help for a cmdlet or function

        (Get-Command -Name Get-Content).Parameters
        Get-help -Name Get-Content -Examples
        Get-help -Name Get-Content -Full
        Get-help -Name Get-Content -Online
    
        (Get-Command -Name Import-Clixml).Parameters
        Get-help -Name Import-Clixml -Examples
        Get-help -Name Import-Clixml -Full
        Get-help -Name Import-Clixml -Online
    
        (Get-Command -Name Select-String).Parameters
        Get-help -Name Select-String -Examples
        Get-help -Name Select-String -Full
        Get-help -Name Select-String -Online
    
        (Get-Command -Name Get-Date).Parameters
        Get-help -Name Get-Date -Examples
        Get-help -Name Get-Date -Full
        Get-help -Name Get-Date -Online
    
        (Get-Command -Name Remove-Item).Parameters
        Get-help -Name Remove-Item -Examples
        Get-help -Name Remove-Item -Full
        Get-help -Name Remove-Item -Online
    

    ... and of course TechNet and MS docs sites.

    PowerShell Documentaiton
    https://docs.microsoft.com/en-us/powershell

    PowerShell Loops
    https://social.technet.microsoft.com/wiki/contents/articles/4542.powershell-loops.aspx

You must be logged in to reply to this topic.