New-TemporaryFile
Creates a temporary file.
Syntax
Default (Default)
New-TemporaryFile
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Description
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.
Examples
Example 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.
Parameters
-Confirm
Prompts you for confirmation before running the cmdlet.
Parameter properties
| Type: | SwitchParameter |
| Default value: | False |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | cf |
Parameter sets
(All)
| Position: | Named |
| Mandatory: | False |
| Value from pipeline: | False |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
-WhatIf
Shows what would happen if the cmdlet runs. The cmdlet is not run.
Parameter properties
| Type: | SwitchParameter |
| Default value: | False |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | wi |
Parameter sets
(All)
| Position: | Named |
| Mandatory: | False |
| Value from pipeline: | False |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
Outputs
FileInfo
This cmdlet returns a FileInfo object that represents the temporary file.