Skip to content

New-TemporaryFile not available when calling powershell.exe from PowerShell 7 through cmd.exe or CreateProcess #14100

Closed
@hero101111

Description

Steps to reproduce

PS C:\test> cmd.exe /c "powershell.exe -command ""New-TemporaryFile"""

Expected behavior

Command to success and return a temporary file path

Actual behavior

Error of "The term 'New-TemporaryFile' is not recognized as the name of a cmdlet, function, script file..."

Environment data

PowerShell 7.1 on Windows 10 x64 version 2004 (for pwsh.exe)
Windows PowerShell 5.1 (for powershell.exe)

Note

When callingPS C:\test> powershell.exe -command "New-TemporaryFile" the command works as expected. It seems that when passing through cmd.exe or ::CreateProcess() the Microsoft.PowerShell.Utility assembly somehow is loaded differently and a few commands, including New-TemporaryFile end up missing.

New-TemporaryFile is available both on PowerShell 7 and on Windows PowerShell 5.1 so this is quite an interesting behavior

Metadata

Assignees

No one assigned

    Labels

    Area-SideBySiderelated to ability to run PS7 side-by-side with WinPS or different versions of PS7Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-No ActivityIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions