New-TemporaryFile

Creates a temporary file.
New-TemporaryFile [-Confirm] [-WhatIf] [<CommonParameters>]

The New-TemporaryFile cmdlet creates an empty file that has the .tmp file name extension. This cmdlet names the file tmpNNNN.tmp, where NNNN is a random hexadecimal number. The cmdlet creates the file in your $Env:Temp folder.

This cmdlet creates temporary files that you can use in scripts.

Parameters
-Confirm [<SwitchParameter>]

  • Default value is false

Prompts you for confirmation before running the cmdlet.Prompts you for confirmation before running the cmdlet.

-WhatIf [<SwitchParameter>]

  • Default value is false

Shows what would happen if the cmdlet runs. The cmdlet is not run.Shows what would happen if the cmdlet runs. The cmdlet is not run.

<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,ErrorAction, ErrorVariable, WarningAction, WarningVariable,OutBuffer, PipelineVariable, and OutVariable.

Outputs

System.IO.FileInfo

This cmdlet returns a FileInfo object that represents the temporary file.

Examples
  1. Create a temporary file:
    PS C:> $TempFile = New-TemporaryFile
    

    This command generates a .tmp file in your temporary folder, and then stores a reference to the file in the $TempFile variable. You can use this file later in your script.