< Back
New-TempDirectory
Post
NAME New-TempDirectory
SYNOPSIS
Creates a new temporary directory.
SYNTAX
New-TempDirectory [[-Prefix] <String>] [<CommonParameters>]
DESCRIPTION
The temporary directory is created in the current user's `TEMP` directory (e.g. `$env:TEMP`). We use
`[IO.Path]::GetRandomFilename` for the directory's name. The directory is returned as a `System.IO.DirectoryInfo`
object.
If/when temporary directories fill up, it can be hard to identify the process(es) responsible. To help identify
which tests are creating (and not removing) temporary directories, supply a unique, static name as the value to
the `Prefix` parameter. We recommend the name of the test fixture creating the temp directory.
PARAMETERS
-Prefix <String>
An optional prefix for the temporary directory name. Helps in identifying tests and things that don't
properly clean up after themselves.
Required? false
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
System.IO.DirectoryInfo.
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>$tempDir = New-TempDirectory
Demonstrates how to create a temporary directory.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>$tempDir = New-TempDirectory 'Test-NewTempDirectory+'
Demonstrates how to use a custom, identifiable prefix for your temporary directory's name. This is helpful for
identfying tests that forget to clean up after themselves.
RELATED LINKS
SYNOPSIS
Creates a new temporary directory.
SYNTAX
New-TempDirectory [[-Prefix] <String>] [<CommonParameters>]
DESCRIPTION
The temporary directory is created in the current user's `TEMP` directory (e.g. `$env:TEMP`). We use
`[IO.Path]::GetRandomFilename` for the directory's name. The directory is returned as a `System.IO.DirectoryInfo`
object.
If/when temporary directories fill up, it can be hard to identify the process(es) responsible. To help identify
which tests are creating (and not removing) temporary directories, supply a unique, static name as the value to
the `Prefix` parameter. We recommend the name of the test fixture creating the temp directory.
PARAMETERS
-Prefix <String>
An optional prefix for the temporary directory name. Helps in identifying tests and things that don't
properly clean up after themselves.
Required? false
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
System.IO.DirectoryInfo.
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>$tempDir = New-TempDirectory
Demonstrates how to create a temporary directory.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>$tempDir = New-TempDirectory 'Test-NewTempDirectory+'
Demonstrates how to use a custom, identifiable prefix for your temporary directory's name. This is helpful for
identfying tests that forget to clean up after themselves.
RELATED LINKS