< Back

New-CTempDirectory

Sun Jan 12, 2020 10:47 pm

NAME New-CTempDirectory



SYNOPSIS

Creates a new temporary directory with a random name.





SYNTAX

New-CTempDirectory [[-Prefix] <String>] [-WhatIf] [-Confirm] [<CommonParameters>]





DESCRIPTION

A new temporary directory is created in the current user's `env:TEMP` directory. The directory's name is created

using the `Path` class's [GetRandomFileName

method](http://msdn.microsoft.com/en-us/library ... ename.aspx).



To add a custom prefix to the directory name, use the `Prefix` parameter. If you pass in a path, only its name

will be used. In this way, you can pass `$MyInvocation.MyCommand.Definition` (PowerShell 2) or `$PSCommandPath`

(PowerShell 3+), which will help you identify what scripts are leaving cruft around in the temp directory.



Added `-WhatIf` support in Carbon 2.0.





PARAMETERS

-Prefix <String>

A prefix to use, so you can more easily identify *what* created the temporary directory. If you pass in a

path, it will be converted to a file name.



Required? false

Position? 1

Default value

Accept pipeline input? false

Accept wildcard characters? false



-WhatIf [<SwitchParameter>]



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Confirm [<SwitchParameter>]



Required? false

Position? named

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:\\>New-CTempDirectory



Demonstrates how to create a new temporary directory, e.g. `C:\\Users\\ajensen\\AppData\\Local\\Temp\\5pobd3tu.5rn`.









-------------------------- EXAMPLE 2 --------------------------



PS C:\\>New-CTempDirectory -Prefix 'Carbon'



Demonstrates how to create a new temporary directory with a custom prefix for its name, e.g.

`C:\\Users\\ajensen\\AppData\\Local\\Temp\\Carbon5pobd3tu.5rn`.









-------------------------- EXAMPLE 3 --------------------------



PS C:\\>New-CTempDirectory -Prefix $MyInvocation.MyCommand.Definition



Demonstrates how you can use `$MyInvocation.MyCommand.Definition` in PowerShell 2 to create a new, temporary

directory, named after the currently executing scripts, e.g.

`C:\\Users\\ajensen\\AppData\\Local\\Temp\\New-CTempDirectory.ps15pobd3tu.5rn`.









-------------------------- EXAMPLE 4 --------------------------



PS C:\\>New-CTempDirectory -Prefix $PSCommandPath



Demonstrates how you can use `$PSCommandPath` in PowerShell 3+ to create a new, temporary directory, named after

the currently executing scripts, e.g. `C:\\Users\\ajensen\\AppData\\Local\\Temp\\New-CTempDirectory.ps15pobd3tu.5rn`.











RELATED LINKS

http://msdn.microsoft.com/en-us/library ... ename.aspx