Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add New-TemporaryDirectory cmdlet - #27549

#27549
Open
KirtiRamchandani wants to merge 8 commits into
PowerShell:masterPowerShell/PowerShell:masterfrom
KirtiRamchandani:feat/new-temporary-directoryKirtiRamchandani/Powershell:feat/new-temporary-directoryCopy head branch name to clipboard
Open

Add New-TemporaryDirectory cmdlet#27549
KirtiRamchandani wants to merge 8 commits into
PowerShell:masterPowerShell/PowerShell:masterfrom
KirtiRamchandani:feat/new-temporary-directoryKirtiRamchandani/Powershell:feat/new-temporary-directoryCopy head branch name to clipboard

Conversation

@KirtiRamchandani

Copy link
Copy Markdown

PR Summary

Add New-TemporaryDirectory to Microsoft.PowerShell.Utility.

The new cmdlet follows the shape of New-TemporaryFile: it supports ShouldProcess, uses low confirmation impact, exports from the Utility module on Windows and Unix, and returns a System.IO.DirectoryInfo for a unique directory under the system temp path.

PR Context

Fixes #25754.

The working group recommended adding New-TemporaryDirectory so users can create temporary directories without calling [System.IO] directly. That matters in constrained and restricted language modes where direct .NET type access is not available.

Validation

  • git diff --check
  • Parsed the touched PowerShell scripts and module manifests with System.Management.Automation.Language.Parser
  • Start-PSBuild -Clean -PSModuleRestore -UseNuGetOrg
  • Start-PSPester -Path test/powershell/Modules/Microsoft.PowerShell.Utility/New-TemporaryDirectory.Tests.ps1 -Tag CI -SkipTestToolBuild -UseNuGetOrg (4 passed)
  • Start-PSPester -Path test/powershell/engine/Basic/DefaultCommands.Tests.ps1 -Tag CI -UseNuGetOrg (290 passed)
  • Manual built-shell smoke test confirmed New-TemporaryDirectory returns System.IO.DirectoryInfo, creates the directory, and places it under [System.IO.Path]::GetTempPath()

PR Checklist

  • I have read the CONTRIBUTING document.
  • If this PR is work in progress, I am opening the PR as a draft.
  • The PR is made against the master branch.
  • My commit messages follow the repository guidelines.
  • I have added tests or validation that prove my fix is effective or that my feature works.
  • I have added necessary documentation, if appropriate.
  • Breaking changes
    • None
  • User-facing changes
  • Testing - New and feature
    • Added focused Pester coverage

Copilot AI review requested due to automatic review settings June 1, 2026 07:31
@KirtiRamchandani
KirtiRamchandani requested a review from a team as a code owner June 1, 2026 07:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds the new New-TemporaryDirectory cmdlet to PowerShell Utility, wires it into module exports/default command verification, and introduces Pester coverage + documentation status update.

Changes:

  • Adds New-TemporaryDirectory cmdlet implementation (NewTemporaryDirectoryCommand.cs).
  • Exports the cmdlet from Microsoft.PowerShell.Utility (Windows/Unix manifests) and registers it in default-command verification.
  • Adds Pester tests for the cmdlet and updates the cmdlet test-status documentation table.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/powershell/engine/Basic/DefaultCommands.Tests.ps1 Adds New-TemporaryDirectory to the default cmdlet/alias verification matrix.
test/powershell/Modules/Microsoft.PowerShell.Utility/New-TemporaryDirectory.Tests.ps1 Introduces Pester coverage for creation/uniqueness/WhatIf/output type.
src/Modules/Windows/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psd1 Exports New-TemporaryDirectory on Windows.
src/Modules/Unix/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psd1 Exports New-TemporaryDirectory on Unix.
src/Microsoft.PowerShell.Commands.Utility/commands/utility/NewTemporaryDirectoryCommand.cs Implements the cmdlet with SupportsShouldProcess and error handling.
docs/testing-guidelines/PowerShellCoreTestStatus.md Marks New-TemporaryDirectory as delivered/tested in the status table.

Comment on lines +44 to +46
It "has an OutputType of System.IO.DirectoryInfo" {
(Get-Command New-TemporaryDirectory).OutputType | Should -BeExactly "System.IO.DirectoryInfo"
}
Comment on lines +21 to +22
string tempPath = Path.GetTempPath();
if (ShouldProcess(tempPath))
Comment on lines +29 to +37
catch (IOException ioException)
{
ThrowTerminatingError(
new ErrorRecord(
ioException,
"NewTemporaryDirectoryWriteError",
ErrorCategory.WriteError,
tempPath));
}
@kilasuit kilasuit added the WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module label Jun 1, 2026
@SteveL-MSFT SteveL-MSFT moved this from Queue to In-Progress-PullRequests in Cmdlets Working Group Jun 17, 2026
@SteveL-MSFT

Copy link
Copy Markdown
Member

The @PowerShell/wg-powershell-cmdlets discussed this. There's an existing older PR (#26679) that attempts to resolve the same issue, however, it appears that author has not followed-up on existing feedback, therefore we recommend moving forward with this PR. However, we ask that the -Prefix parameter be added to this PR.

@SteveL-MSFT SteveL-MSFT added the WG-Reviewed A Working Group has reviewed this and made a recommendation label Jun 17, 2026
@SteveL-MSFT SteveL-MSFT moved this from In-Progress-PullRequests to Reviewed in Cmdlets Working Group Jun 17, 2026
Expose Directory.CreateTempSubdirectory prefix support and add Pester
coverage for custom directory name prefixes.
@KirtiRamchandani
KirtiRamchandani force-pushed the feat/new-temporary-directory branch from 969ef08 to 06d71c7 Compare June 17, 2026 17:13
@jshigetomi jshigetomi added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Jun 22, 2026
@jshigetomi jshigetomi self-assigned this Jun 22, 2026
@jshigetomi

Copy link
Copy Markdown
Collaborator

@SteveL-MSFT @kilasuit @Thatgfsj
This PR and #27086 are address the same thing. WG recommends this. This PR address more tests cases and captures UnauthorizedAccess Exception.

@sdwheeler sdwheeler left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add HelpUri

/// <summary>
/// The implementation of the "New-TemporaryDirectory" cmdlet.
/// </summary>
[Cmdlet(VerbsCommon.New, "TemporaryDirectory", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Low)]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add this HelpUri

Suggested change
[Cmdlet(VerbsCommon.New, "TemporaryDirectory", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Low)]
[Cmdlet(VerbsCommon.New, "TemporaryDirectory", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Low, HelpUri = "https://go.microsoft.com/fwlink/?LinkId=2097032")]

@microsoft-github-policy-service microsoft-github-policy-service Bot added the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Jun 24, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Jun 27, 2026
@KirtiRamchandani

Copy link
Copy Markdown
Author

@jshigetomi @SteveL-MSFT @sdwheeler Are we good to merge this?

@kilasuit kilasuit added WG-Cmdlets general cmdlet issues and removed WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module labels Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log WG-Cmdlets general cmdlet issues WG-Reviewed A Working Group has reviewed this and made a recommendation

Projects

Status: Reviewed

Development

Successfully merging this pull request may close these issues.

New-TemporaryDirectory or New-TemporaryItem or New-Item -Temporary

6 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.