Private/Remove-HPSTmpFile.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
48
49
50
51
52
53
54
Function Remove-HPSTmpFile {

    <#
        .SYNOPSIS
        n/a

        .DESCRIPTION
        n/a

        .PARAMETER Extension
        n/a

        .EXAMPLE
        Remove-HPSTmpFile -Path "C:\Windows\Temp\cc20c224-85bb-4008-b3dd-25d732fa7d98.inf"

        .INPUTS
        System.String

        .LINK
        https://hardening.thomas-illiet.fr/Private/Remove-HPSTmpFile/

        .LINK
        https://github.com/thomas-illiet/Hardening/blob/stable/Hardening/Private/Remove-HPSTmpFile.ps1

        .NOTES
        - File Name : Remove-HPSTmpFile.ps1
        - Author : Thomas ILLIET
    #>


    [CmdletBinding( HelpUri = "https://hardening.thomas-illiet.fr/Private/Remove-HPSTmpFile/" )]
    [OutputType( [System.Void] )]
    Param(
        [Parameter(Mandatory = $true)]
        [System.String]
        $Path
    )

    begin {
        Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started"
    }

    process {
        $TempPath = [System.IO.Path]::GetTempPath()
        if ( (Test-Path -Path $Path) -and ( $Path -like "${TempPath}*" ) ) {
            Remove-Item -Path $Path -Force
        }
    }

    end {
        Write-Verbose "[$($MyInvocation.MyCommand.Name)] Complete"
    }

}