New-TemporaryDirectory
Creates a new temporary directory.
Syntax
__AllParameterSets
New-TemporaryDirectory
[-Prefix <string>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Description
This command creates a new temporary directory in the system's temporary folder and returns a
DirectoryInfo object representing the newly created directory. The name of the temporary directory
is generated using a unique identifier, and you can optionally specify a prefix for the directory
name.
Examples
Example 1 - Create a temporary directory with a prefix
New-TemporaryDirectory -Prefix sdw
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 9/1/2026 9:11 AM sdwyckmvjd0.mkh
Parameters
-Confirm
Prompts you for confirmation before running the cmdlet. The command uses low confirmation impact.
Parameter properties
| Type: | SwitchParameter |
| 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 |
-Prefix
Allows you to specify a prefix for the directory name, which can help in identifying the purpose of the temporary directory.
Parameter properties
| Type: | String |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
(All)
| Position: | Named |
| Mandatory: | False |
| Value from pipeline: | False |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
-WhatIf
Runs the command in a mode that only reports what would happen without performing the actions.
Parameter properties
| Type: | SwitchParameter |
| 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.