Search code examples
powershellinvoke-command

Invoke-Command is giving NativeCommandError


I am using Invoke-Command { & "powershell.exe" } -NoNewScope and getting error as belove.

powershell.exe : Loading personal and system profiles took 1761ms.
At line:1 char:18
+ Invoke-Command { & "powershell.exe" } -NoNewScope
+                  ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Loading persona...es took 1761ms.:String 
   ) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

Error Image


Solution

  • This is...

    Invoke-Command { & "powershell.exe" } -NoNewScope
    

    ... is for the console host based on your use case.

    If you are in the ISE, enter image description here

    ... you must use New PowerShell Tab option, to get a new session and your profile will load there.

    enter image description here

    You can use the shortcut key of course. CRTL+T

    enter image description here

    Differences between the ISE and PowerShell console - PowerShell Team

    Console Application (Non) Support in the ISE

    $psUnsupportedConsoleApplications
    # Results
    <#
    wmic
    wmic.exe
    cmd
    cmd.exe
    diskpart
    diskpart.exe
    edit.com
    netsh
    netsh.exe
    nslookup
    nslookup.exe
    powershell
    powershell.exe
    ssh-keygen
    ssh-keygen.exe
    #>
    

    PowerShell- Running Executables - TechNet Articles - United States (English) - TechNet Wiki