Home » PowerShell » Use PowerShell to Get Temp Folder Path

Use PowerShell to Get Temp Folder Path

Use the environment variable `$env:Temp` to get the temp folder in PowerShell. This variable returns the current user’s temp folder path.

The temp folder in Windows is a directory used by the operating system and applications to store temporary files.

In this tutorial, we will discuss how to get the temp folder path using the environment variable Env:temp and [System.IO.Path]::GetTempPath() in PowerShell.

Use Env:Temp to Find Temp Folder Path using PowerShell

The PowerShell Environment (Env:) drive exposes environment variables as a file system. Using the temp variable, allows you to interact and access a specific environment variable.

$env:TEMP

The above PowerShell script retrieves the current user’s temp directory path.

The output of the above script to get the location of the temp folder is:

PowerShell Get Temp Folder Path
PowerShell Get Temp Folder Path
PS C:\> $env:Temp                                                                                                                                                                            C:\Users\shelladmin\AppData\Local\Temp

PS C:\>     

Use GetTempPath() to Get Temp Directory Path in PowerShell

The .NET class [System.IO.Path] has a static method called the GetTempPath() method that returns the path of the current user’s temporary folder.

[System.IO.Path]::GetTempPath()

The above PowerShell script gets the temp folder location as given below.

PS C:\> [System.IO.Path]::GetTempPath()                                                                                                                                                      C:\Users\shelladmin\AppData\Local\Temp\

Conclusion

I hope the above article on how to get the temp folder path using PowerShell is helpful to you.

By leveraging environment variables and built-in methods in PowerShell, you can find the temp folder in Windows and access and manage the temp folder, like creating a temporary file in the temp folder or cleaning up the temp folder.