Private/New-HPSTmpFile.ps1

Function New-HPSTmpFile {

    <#
        .SYNOPSIS
        n/a

        .DESCRIPTION
        n/a

        .PARAMETER Extension
        n/a

        .EXAMPLE
        New-HPSTmpFile -Extension inf

        .INPUTS
        System.String

        .OUTPUTS
        System.String

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

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

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


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

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

    process {
        # Set the name and path of the temporary file
        $Path     = [System.IO.Path]::GetTempPath()
        $FileName = [System.Guid]::NewGuid().ToString() + '.' + $Extension
        $FilePath = [System.IO.Path]::Combine($Path, $FileName)

        # Create a temporary file
        if( (Test-Path -Path $FilePath) -eq $False ) {
            Return (New-Item -Path $FilePath -ItemType File).FullName
        }
        else {
            Write-Error "Cannot create a temporary file when that file already exists : ${FilePath}"
        }
    }

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