New-TemporaryFile not available when calling powershell.exe from PowerShell 7 through cmd.exe or CreateProcess #14100
Closed
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