PowerShell 5 introduces the New-TemporaryFile cmdlet, which is handy. How can I do the same thing but instead of a file create a directory? Is there a New-TemporaryDirec
Here's a variant of user4317867's answer. I create a new directory in the user's Windows "Temp" folder and make the temp folder path available as a variable ($tempFolderPath
):
$tempFolderPath = Join-Path $Env:Temp $(New-Guid)
New-Item -Type Directory -Path $tempFolderPath | Out-Null
Here's the same script available as a one-liner:
$tempFolderPath = Join-Path $Env:Temp $(New-Guid); New-Item -Type Directory -Path $tempFolderPath | Out-Null
And here's what the fully qualified temp folder path ($tempFolderPath
) looks like:
C:\Users\MassDotNet\AppData\Local\Temp\2ae2dbc4-c709-475b-b762-72108b8ecb9f