Skip to content

Add New-TemporaryDirectory cmdlet - #27549

Merged
Justin Chung (jshigetomi) merged 11 commits into
PowerShell:masterfrom
KirtiRamchandani:feat/new-temporary-directory
Aug 17, 2026
Merged

Justin Chung (jshigetomi) merged 11 commits into
PowerShell:masterfrom
KirtiRamchandani:feat/new-temporary-directory

Conversation

@KirtiRamchandani

Copy link
Copy Markdown
Contributor

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

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.

@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 Steve Lee (SteveL-MSFT) added the WG-Reviewed A Working Group has reviewed this and made a recommendation label Jun 17, 2026
@SteveL-MSFT Steve Lee (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.
@jshigetomi Justin Chung (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

Copy link
Copy Markdown
Collaborator

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

@sdwheeler Sean Wheeler (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

@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
Contributor Author

@KirtiRamchandani

Copy link
Copy Markdown
Contributor Author

Justin Chung (@jshigetomi) Steve Lee (@SteveL-MSFT) can we close/merge this branch?

@KirtiRamchandani

Copy link
Copy Markdown
Contributor Author

Justin Chung (@jshigetomi) All checks passed. :)

LGTM, or should I rebase this before merging?

@jshigetomi

Copy link
Copy Markdown
Collaborator

Kirtikumar Anandrao Ramchandani (@KirtiRamchandani) give me one second let me review it. I think you brought over most or all changes suggested in the other PR

@jshigetomi

Copy link
Copy Markdown
Collaborator

Ryan Yates (@kilasuit) Steve Lee (@SteveL-MSFT) Kirtikumar Anandrao Ramchandani (@KirtiRamchandani) Sorry about the back and forth with the other PR. I wanted to give the other author a chance to contribute since he created the PR first. This change has been delayed for a while because of it, and I don't think it justifies any more delay when this PR is ready to go.

@KirtiRamchandani

Copy link
Copy Markdown
Contributor Author

Justin Chung (@jshigetomi), that was quick, thanks! Yes, while suggesting a change that I discovered as an edge case in the other PR, I got it fixed here too. :P

@KirtiRamchandani

Copy link
Copy Markdown
Contributor Author

Ryan Yates (@kilasuit) Steve Lee (@SteveL-MSFT) Kirtikumar Anandrao Ramchandani (@KirtiRamchandani) Sorry about the back and forth with the other PR. I wanted to give the other author a chance to contribute since he created the PR first. This change has been delayed for a while because of it, and I don't think it justifies any more delay when this PR is ready to go.

Completely fine and understandable as a reviewer to give a chance to the first to make a PR. And yeah, that was good of these reviewers to give a fair chance. :)

Thank you very much!

@kilasuit

Copy link
Copy Markdown
Collaborator

In the other PR #27086 this Testing Guidelines File was also updated

Justin Chung (@jshigetomi) does this file also need updating in this PR as it was updated with the Addition of New-TemporaryFile command but as far as I can tell hasn't been consistently being updated as this project has evolved & it may actually make more sense to decide on what the future is for that file going forward & if it needs updating in a separate Repo Docs PR.

@jshigetomi

Copy link
Copy Markdown
Collaborator

Ryan Yates (@kilasuit) That is a good point. I will bring this up with the maintainers

@jshigetomi
Justin Chung (jshigetomi) merged commit f83ccdd into PowerShell:master Aug 17, 2026
36 checks passed
@iSazonov

Copy link
Copy Markdown
Collaborator

Justin Chung (@jshigetomi) You must have been too hasty. This code requires correction in almost every line, it is better to cancel it than fix it.

@KirtiRamchandani

Copy link
Copy Markdown
Contributor Author

Ilya (@iSazonov) maybe we can have a followup pr? Can you list the specific lines or patterns you like to be changed? I will make a pr to polish this shortly trying to identify the lines, I think I can infer the ones you are pointing to.

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

7 participants