2

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

tech189
  • 303
  • 2
  • 10
  • 1
    What is *starship*? You're referencing the official website. Why don't you provide it? The official help for [Invoke-Expression](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-expression?view=powershell-7.1) shows that the command should be a string enclosed in quotes or double quotes. Why are you using parenthesis? If `starship` is an external executable shouldn't `Invoke-Command` be the better option for this purpose? – Olaf Sep 05 '21 at 19:10
  • 1
    Yes. After adding "" quotation, it seems to work. Thank you so much for the edit. – Abu Sayeed Mondal Sep 06 '21 at 01:37

4 Answers4

3

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.

0

You need to activate the execution of PowerShell scripts first. To do so, run the following command as Administrator:

Set-ExecutionPolicy RemoteSigned
0

Invoke-Expression (& 'C:\Program Files\starship\bin\starship.exe' init powershell)

in your $PROFILE after installing starship with winget install starship.

bgausden
  • 71
  • 2
0

Add-Content -Path $PROFILE -Value 'Invoke-Expression (&starship init powershell)'

Set-ExecutionPolicy RemoteSigned -Force

Esteban Ortega
  • 155
  • 1
  • 8