Powershell and VS Code does not recognize "Set-Location"

Asked

Viewed 1,936 times

0

Man PowerShell does not recognize the Set-Location, this has been happening for a while now every time I run a code in VS Code because my work and projects are in the cloud and on another HD but I never gave any importance because it ran normal.

But now I can’t open any terminal in the folder itself or browse by switching Hds

Error:

Set-Location : O termo 'Set-Location' não é reconhecido como nome de cmdlet, função, arquivo de script ou programa
operável. Verifique a grafia do nome ou, se um caminho tiver sido incluído, veja se o caminho está correto e tente
novamente.
No linha:1 caractere:1
+ Set-Location -Path 'G:\OneDrive\Gui\GuiTestes\Python\Projetos ...
+ ~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Set-Location:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

(This is the same error that appears in the VS Code terminal)

.

I checked in the PowerShell ISE the "installed" controls and the Set-Location does not actually appear (and also another command set-variable, I found out going into the ISE):

inserir a descrição da imagem aqui

  • Ever tried to use Import-Module -Name Microsoft.PowerShell.Management before the Set-Location?

  • OK.. This worked, but I’ll need to do it manually when I need to use Set-Location or any other command. Not some way to fix it?

  • Are you using Windows 10? If you’re not checking the Powershell version, I had a similar problem trying to run a script on a Windows 7 and had to install the newer version of Powershell

  • Could have used pushd and popd who perform the same function.

  • I didn’t know these commands. But from what I could tell, it wasn’t just the Set-Location that was with this error, other commands are with this problem. But obr

1 answer

0


Good. I managed to solve.

Really if you add before any command (native to Powersheel) the line Import-Module -Name Microsoft.PowerShell.Management and then the Powershell command itself (which is not recognizing) works.

But it just solves it manually and it sucks to be doing it..

(opened Powershell in the folder, gave error and then I did the commands)

.

Installing the new PowerShell

What I did was install the new PowerShell 7.0 (most current version) The version I downloaded was the PowerShell-7.0.3-win-x64.msi (89 Mb) in that repository.

The version .msi installs directly and Windows itself already configures. Already the version .zip It is as if you have copied the program to your computer, that is, it is not actually installed with the system but it is accessible. I suggest lowering the .msi.

The PowerSheel 7.0 does not disguise the PowerShell 5, Microsoft itself says this, they kind of work together. But it appears straight with the right mouse button and tb with the shift + x, can even choose whether you want as Adm or not:

inserir a descrição da imagem aqui

.

Adjusting the VS Code terminal:

How VS Code has its integrated terminal, which is nothing more than Powershell (you can see by PS written at the beginning of the line), in the configurations you can change the terminal, you can choose which you want (it can be any of your preference, until some you downloaded).

In that link shows how to change the terminal. If you have another problem with the terminal, this link gives you some alternatives.

inserir a descrição da imagem aqui

My suggestion for you to install this new PowerShell 7.0, is worth a lot and eh more 'clean'.

  • It was just a case of putting that line on Import-Module within a global profile so all started shells would already import the module or else a specific profile so that only the chosen profile would start with the module load. Reading suggestion Powershell || About Profiles

  • I found it easier to install the new one, which even appears when I right click. But by the tip

Browser other questions tagged

You are not signed in. Login or sign up in order to post.