Remove-HTTempFolder.ps1

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
44
45
46
47
function Remove-HTTempFolder
{
    [CmdletBinding()]
    param
    (
        [parameter(Position = 0)]
        [string]$FolderName,
        [switch]$FlushTemp
    )
    
    process
    {
        
        
        $root_folder = Join-Path $env:TEMP 'HTToolsTemp'
        
        if (-not (Test-Path $root_folder))
        {
            return "Root Temp Folder not initialized..,"
        }
        
        if ($FlushTemp)
        {
            Remove-Item $root_folder -Confirm:$false -Recurse
            
            return "All data in temp folder deleted..."
        }
        
        if ($FolderName -eq '')
        {
            return
        }
        
        $FolderName = Join-Path $root_folder $FolderName
        
        if (-not (Test-Path $FolderName))
        {
            return "$FolderName not found... "
        }
        
        Remove-Item $FolderName -Recurse -Confirm:$false
        
        
    }
    
}