Wget Path Environment Variable on Windows - powershell

On Windows 10, I installed Wget by choco install wget.
Then I added wget.exe location folder to Path Environment Variable (which at the time of installation was C:\ProgramData\chocolatey\lib\Wget\tools).
However, Wget commands using PowerShell / cmd, like wget --help and wget [any_link] don't work right away, they work only if I type wget.exe --help and wget.exe [any_link]
wget --help error:
wget : The remote name could not be resolved: '--help'
At line:1 char:1
+ wget --help
+ ~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
How to disable explicit .exe extension? I know it's a minor problem, but when you do not use Wget very often, each time it takes you some time recollecting this annoying detail...

This is because Powershell already has its own wget command defined, that actually is an alias of Invoke-WebRequest cmdlet. If you remove the alias you can use wget.exe command without the file extension. Just try
Remove-Item Alias:wget
wget --help

Related

Error trying to list files in directory using the ls -la command

So this command I'm trying to use to list all the files in my directory (my github repo that I cloned to vsc) doesn't seem to work. Vsc is on the latest version.
PS C:\VSCode\Git\test> ls -la
Get-ChildItem : A parameter cannot be found that matches parameter
name 'la'.
At line:1 char:4
+ ls -la
+ ~~~
+ CategoryInfo : InvalidArgument: (:) [Get-ChildItem],
ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
You are using Powershell on Windows. In Powershell on Windows, ls is an alias for Get-ChildItem. It is not the ls command as provided on *nix.
Use one of the following commands instead.
Get-ChildItem -Force
Get-ChildItem -Attributes Normal, Directory, Hidden
(Note that this is not a git issue and not a Visual Studio Code issue.)

Activate a virtual environment in Windows Powershell with a command that is equivalent to "source"

I need to activate a virtual environment in Windows Powershell. But, the guide i am using that to proceed my project tells me to use a command like this:
source venv-slither/bin/activate
In my project directory, in first, i installed virtualenv with:
pip3 install virtualenv
After that, I setup a virtual environment in folder ./venv-slither with:
source venv-slither/bin/activate
Problem emerges here. Whenever i run the last command i approaches to this message in Powershell:
source : The term 'source' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At line:1 char:2
+ source venv-slither/bin/activate
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (source:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I read some guide to eliminate this. They suggest using . instead source, but by this way the same error occurs. When, my Command is:
. venv-slither/bin/activate
The message is:
. : The term 'venv-slither/bin/activate' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct
and try again.
At line:1 char:3
+ . venv-slither/bin/activate
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (venv-slither/bin/activate:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
More over, when i change slashes direct:
. venv-slither\bin\activate
This message comes up:
. : The module 'venv-slither' could not be loaded. For more information, run 'Import-Module venv-slither'.
At line:1 char:3
+ . venv-slither\bin\activate
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (venv-slither\bin\activate:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoLoadModule
I have these modules in my project directory: .bin, dot, findit, source.
Please help a beginner man in working with Windows Powershell.
I think you should use like this, within Windows PS:
venv-slither/Scripts/activate.ps1
After enabling the necessary execution policy for the current user with this command:
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser
I would return to previous policy with this command, after you finish your work, for safety:
Set-ExecutionPolicy -ExecutionPolicy Undefined -Scope CurrentUser
There are other ways to set the execution temporarily. For example, I can set for the current PS's session by issuing this command:
powershell.exe -ExecutionPolicy RemoteSigned
* RemoteSigned or Unrestricted, you can refer to this link to view the details which scripts are or not allowed for each type of policy:
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.1
Sorry for posting too late, I've just run into your post when found the same issue, tested myself and it worked.

Not able to execute the "Import-module"

I get below error when i try to execute the command "Import-module script.ps1"
any idea why is that shows up? what need to be done to resolve the issue ?
PS C:\File> Import-module script.ps1
Import-module : The specified module 'script.ps1' was not loaded because no valid module file was found in any module directory.
At line:1 char:1
+ Import-module script.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (script.ps1:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
You need to use .\ to execute scripts, commands from current directory. i.e. ipmo .\script.ps1
As a security feature, PowerShell does not run executable (native)
commands, including PowerShell scripts, unless the command is located
in a path that is listed in the Path environment variable $env:path or
unless you specify the path to the script file.
To run a script that is in the current directory, specify the full
path, or type a dot .\ to represent the current directory.
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_command_precedence?view=powershell-7

Cannot install psget

I am trying to install psget on windows 10 from powershell in admin mode but I get:
PS C:\Windows\system32> (new-object Net.WebClient).DownloadString("http://psget.net/GetPsGet.ps1") | iex
Downloading PsGet from https://github.com/psget/psget/raw/master/PsGet/PsGet.psm1
Invoke-WebRequest : The given path's format is not supported.
At line:42 char:13
+ Invoke-WebRequest -Uri $Url -OutFile $SaveToLocation
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotImplemented: (:) [Invoke-WebRequest], NotSupportedException
+ FullyQualifiedErrorId : WebCmdletIEDomNotSupportedException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Import-Module : The specified module 'C:\Users\myuser\Documents\WindowsPowerShell\Modules C:\Users\myuser\Documents\WindowsPowerShell\Modules\PsGet' was not loaded
because no valid module file was found in any module directory.
At line:105 char:9
+ Import-Module -Name $Destination\PsGet
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (C:\Users\myuser\Do...l\Modules\PsGet:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
PsGet is installed and ready to use
USAGE:
PS> import-module PsGet
PS> install-module PsUrl
For more details:
get-help install-module
Or visit http://psget.net
PS C:\Windows\system32>
As suggested below PsGet is actually already installed on windows 10. I have then continued with the next step:
and as can be seen it installs successfully (needs to be done running as administrator). After a restart of the powershell console I still don't get any color highlighting though:
Any ideas?
Btw: the folder C:\Users[my-user]\Documents\WindowsPowerShell\Modules is empty:
Um... psget as in PowerShellGet module that I am almost certain comes on Win 10. I believe your error is even telling you that. Where it says PsGet is installed and ready to use.
Looks like the script at http://psget.net/GetPsGet.ps1 tries to decide where to install by querying for #($env:PSModulePath -split ';') and then limit the search for paths under Documents\WindowsPowerShell\Modules.
It appears that in your computer, PSModulePath includes twice the folder C:\Users\myuser\Documents\WindowsPowerShell\Modules, which causes an issue with the installation script.
You can do either one of these two options to solve it:
Remove one instance of C:\Users\myuser\Documents\WindowsPowerShell\Modules from the PSModulePath variable.
Install PsGet manually using the instructions in the official website.

Alias syntax for Firefox 'cfx run -profile <dir>'

I would like to know how to do set-alias in PowerShell for the cmd used in developing Firefox extension:
cfx run -p C:\Users\username\AppData\Roaming\Mozilla\Firefox\Profiles\ripltbxm.cfxp
I've added the following to Microsoft.PowerShell_profile.ps1:
Set-Alias cfxp cfx run -p "C:\Users\username\AppData\Roaming\Mozilla\Firefox\Profiles\ripltbxm.cfxp"
But when PowerShell is launched, it shows the error:
Set-Alias : A positional parameter cannot be found that accepts argument 'run'.
At D:\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:2 char:1
+ Set-Alias cfxp cfx run -p "C:\Users\username\AppData\Roaming\Mozilla\Firefox\Profil ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-Alias], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SetAliasCommand
Also tried:
Set-Alias cfxp "cfx run -p C:\Users\username\AppData\Roaming\Mozilla\Firefox\Profiles\ripltbxm.cfxp"
with another error:
cfxp : The term 'cfx run -p C:\Users\username\AppData\Roaming\Mozilla\Firefox\Profiles\ripltbxm.cfxp' is not recognized
as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At line:1 char:1
+ cfxp
+ ~~~~
+ CategoryInfo : ObjectNotFound: (cfx run -p C:\U...s\ripltbxm.cfxp:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
In PowerShell aliases can be defined only for commands or cmdlets, not for entire commandlines with parameters:
NAME
New-Alias
SYNOPSIS
Creates a new alias.
[...]
DESCRIPTION
The New-Alias cmdlet creates a new alias in the current Windows
PowerShell session. Aliases created by using New-Alias are not
saved after you exit the session or close Windows PowerShell. You
can use the Export-Alias cmdlet to save your alias information to
a file. You can later use Import-Alias to retrieve that saved
alias information.
PARAMETERS
[...]
-Value <String>
Specifies the name of the cmdlet or command element that is
being aliased.
You'll need a custom function if you want a shorthand for running a particular command with parameters.
function cfxp {
& cfx run -p "$env:APPDATA\Mozilla\Firefox\Profiles\ripltbxm.cfxp"
}