Executing a command stored in a variable from PowerShell

Here is yet another way without Invoke-Expression but with two variables (command:stringĀ andĀ parameters:array). It works fine for me. Assume 7z.exe is in the system path. $cmd = ‘7z.exe’ $prm = ‘a’, ‘-tzip’, ‘c:\temp\with space\test1.zip’, ‘C:\TEMP\with space\changelog’ & $cmd $prm If the command is known (7z.exe) and only parameters are variable then this will do $prm = … Read more

Use Invoke-WebRequest with a username and password for basic authentication on the GitHub API

I am assuming Basic authentication here. $cred = Get-Credential Invoke-WebRequest -Uri ‘https://whatever’ -Credential $cred You can get your credential through other means (Import-Clixml, etc.), but it does have to be a [PSCredential] object. Edit based on comments: GitHub is breaking RFC as they explain in the link you provided: The API supports Basic Authentication as … Read more

Select the values of one property on all objects of an array in PowerShell

I think you might be able to use the ExpandProperty parameter of Select-Object. For example, to get the list of the current directory and just have the Name property displayed, one would do the following: ls | select -Property Name This is still returning DirectoryInfo or FileInfo objects. You can always inspect the type coming … Read more

How to make PowerShell tab completion work like Bash

New versions of PowerShell include PSReadline, which can be used to do this: Set-PSReadlineKeyHandler -Key Tab -Function Complete or, to make it even more like bash where you can use arrow-keys to navigate available options: Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete To make it permanent, put this command into C:\Users\[User]\Documents\WindowsPowerShell\profile.ps1.

Can’t install nuget package because of “Failed to initialize the PowerShell host”

Setting an execution policy to RemoteSigned or Unrestricted should work. It must be changed under an administrator mode via a PowerShell console. Be aware that changes will be applied according to the bit version of the PowerShell console, so 32bit or 64 bit. So if you want to install a package in Visual Studio (32 … Read more

Visual studio code cmd error: Cannot be loaded because running scripts is disabled on this system

I found out here that you can add to your visual studio code settings the following and the problem will vanish: For visual studio code settings, go to File -> Preferences -> Settings -> Extensions -> Scroll down and find “Edit in settings.json”. Do not forget to restart the visual studio code “terminal.integrated.shellArgs.windows”: [“-ExecutionPolicy”, “Bypass”] … Read more