New-TemporaryFile

Creates a temporary file.

语法

Default (默认值)

New-TemporaryFile
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

说明

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

The New-TemporaryFile cmdlet creates an empty file that has the .tmp file name extension. This cmdlet names the file tmp<NNNN>.tmp, where <NNNN> is a random hexadecimal number. The cmdlet creates the file in your TEMP folder.

This cmdlet uses the Path.GetTempPath() method to find your TEMP folder. This method checks for the existence of environment variables in the following order and uses the first path found:

  • On Windows platforms:

    1. The path specified by the TMP environment variable.
    2. The path specified by the TEMP environment variable.
    3. The path specified by the USERPROFILE environment variable.
    4. The Windows directory.
  • On non-Windows platforms: Uses the path specified by the TMPDIR environment variable.

示例

Example 1: Create a temporary file

$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.

参数

-Confirm

Prompts you for confirmation before running the cmdlet.

参数属性

类型:SwitchParameter
默认值:False
支持通配符:False
不显示:False
别名:cf

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-WhatIf

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

参数属性

类型:SwitchParameter
默认值:False
支持通配符:False
不显示:False
别名:wi

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值: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.

输出

FileInfo

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