Search code examples
windowspowershellcmdcommand-linescoop-installer

Error adding Starship command line in Windows PowerShell profile


I added scoop, then Starship just as the Starship official website says using the command scoop install starship. Then I added the line copied from the Starship website to the PowerShell profile:

Invoke-Expression (&starship init powershell)

But it throws this error to the PowerShell window: Invoke-Expression : Cannot bind argument to parameter 'Command' because it is null.

This is the only line in my PowerShell $Profile.

But where is the problem, can you please figure out? The error is in the image below:

enter image description here


Solution

  • Simple solution

    Invoke-Expression (& 'C:\Users\psayeed1990\scoop\apps\starship\current\starship.exe' init powershell --print-full-init | Out-String)
    

    Change the link of your starship.exe as you need.

    For further read, This is how I solved this...

    Creating the file with notepad didn't work for me

    First, if your PowerShell $profile doesn't exist, create a profile with this command in command line (creating the file with Notepad doesn't work).

    if (!(Test-Path -Path $PROFILE)) {
    
      New-Item -ItemType File -Path $PROFILE -Force
    
    }
    

    Second, if you command notepad $profile, you can see, edit and save the file. Copy this code from official Starship site and paste it in the end of the $profile file Invoke-Expression (&starship init powershell).

    Third, if it doesn't work, you may want to install vcredist2019. scoop install vcredist2019 didn't work for me. So, I downloaded from the official site.

    Fourth, installing the vcredist2019 didn't solve it too. As @Olaf pointed out in the comment, you need quotation mark instead of parentheses, Invoke-Expression "&starship init powershell".

    I don't think quotation is the way to write. If you restart your PowerShell and it doesn't work yet, you may still see a error or a line giving you the command with exact path to the Starship executable.

    Fifth, replace the above code Invoke-Expression "&starship init powershell" in the $profile with that line.

    Invoke-Expression (& 'C:\Users\psayeed1990\scoop\apps\starship\current\starship.exe' init powershell --print-full-init | Out-String)
    

    I hope this works.