functions/clear-d365monitordata.ps1


<#
    .SYNOPSIS
        Clear the monitoring data from a Dynamics 365 for Finance & Operations machine
         
    .DESCRIPTION
        Clear the monitoring data that is filling up the service drive on a Dynamics 365 for Finance & Operations
         
    .PARAMETER Path
        The path to where the monitoring data is located
         
        The default value is the "ServiceDrive" (j:\ | k:\) and the \MonAgentData\SingleAgent\Tables folder structure
         
    .EXAMPLE
        PS C:\> Clear-D365MonitorData
         
        This will delete all the files that are located in the default path on the machine.
        Some files might be locked by a process, but the cmdlet will attemp to delete all files.
         
    .NOTES
        Author: Mötz Jensen (@Splaxi)
         
#>

function Clear-D365MonitorData {
    [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
    [CmdletBinding()]
    param (
        [Parameter(Position = 1, ValueFromPipelineByPropertyName = $true, ValueFromPipeline = $true)]
        [string] $Path = (Join-Path ([System.Environment]::ExpandEnvironmentVariables("%ServiceDrive%")) "\MonAgentData\SingleAgent\Tables")
    )
    
    Get-ChildItem -Path $Path | Remove-Item -Force -ErrorAction SilentlyContinue
}