Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stanislavhordiyenko/351dca11b881b5394475ad5f10640bf6 to your computer and use it in GitHub Desktop.
Save stanislavhordiyenko/351dca11b881b5394475ad5f10640bf6 to your computer and use it in GitHub Desktop.
Create Temporary Files in PowerShell
# Create temporary file with PowerShell 4 or lower
$TempFile = [System.IO.Path]::GetTempFileName()
Write-Output "Temporary file has been created. It is located here: $($TempFile)"
Remove-Item $TempFile -Force
# Create temporary file with PowerShell 5
$TempFile = New-TemporaryFile
Write-Output "Temporary file has been created. It is located here: $($TempFile)"
Remove-Item $TempFile.FullName -Force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment