You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Creates a new temporary directory and returns a DirectoryInfo object.
Parameters
Parameter
Type
Required
Description
-Prefix
String
No
Specifies a prefix for the temporary directory name
Examples
# Create a temporary directory$tempDir=New-TemporaryDirectory# Create a temporary directory with a prefix$tempDir=New-TemporaryDirectory-Prefix "MyApp_"
Notes
Uses .NET's Directory.CreateTempSubdirectory() API
Activity
Thatgfsj commentedon Jun 21, 2026
Note: There is also an alternative implementation PR at PowerShell/PowerShell#27086 (by Thatgfsj (@Thatgfsj)) that adds the same
New-TemporaryDirectorycmdlet.The Cmdlets Working Group is currently deciding which PR to accept (see PR #27086 comment).
Implementation details for PR #27086:
New-TemporaryFilepattern exactlydo/whileloop withDirectoryInfo.Existscheck to avoid name collisions (matchingPathUtils.CreateTemporaryDirectory()pattern)-WhatIfand-ConfirmviaShouldProcessSystem.IO.DirectoryInfo