Get-PSReadLineKeyHandler : A parameter cannot be found that matches parameter name 'Key'. What is this in Oh My Posh? - powershell

Get-PSReadLineKeyHandler : A parameter cannot be found that matches parameter name 'Key'.
At line:380 char:43
+ if ((Get-PSReadLineKeyHandler -Key Spacebar).Function -eq ...
+ ~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-PSReadLineKeyHandler], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.GetKeyHandlerCommand
Get-PSReadLineKeyHandler : A parameter cannot be found that matches parameter name 'Key'.
At line:383 char:43
+ if ((Get-PSReadLineKeyHandler -Key Enter).Function -eq 'O ...
+ ~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-PSReadLineKeyHandler], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.GetKeyHandlerCommand
This appears everytime whenever I open my powershell. What can I do to fix this?
Looking for a solution.

You need to update the PSReadLine module. Run:
Install-Module PsReadLine -Force

Related

How to call a powershell script to another powershell script with arguments?

I just need to call another script and pass the parameters to it.
I tried doing invoke-expression to access it, i tried using &, and nothing worked
I tried doing the following:
$hostfile = "C:\Users\username\Desktop\csvfile_test.csv"
$outFile = ".\testerFile.xlsx"
& '.\organizer.ps1' "-csvFile $hostfile -outputPath $outFile "
Invoke-Expression 'C:\Users\username\Desktop\organizer.ps1' "$hostfile $outFile"
I receive the following errors:.
with ampersand (&):
PS C:\Users\username\Desktop> C:\Users\username\Desktop\scanner.ps1
Exception calling "ReadLines" with "1" argument(s): "The given path's format is not supported."
At C:\Users\username\Desktop\scanner.ps1:48 char:1
+ [System.IO.File]::ReadLines("$csvFile") | ForEach-Object {
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : NotSupportedException
with invoke-expression:
Exception calling "ReadLines" with "1" argument(s): "The given path's format is not supported."
At C:\Users\username\Desktop\scanner.ps1:48 char:1
+ [System.IO.File]::ReadLines("$csvFile") | ForEach-Object {
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : NotSupportedException
Invoke-Expression : A positional parameter cannot be found that accepts argument 'C:\Users\username\Desktop\csvfile_test.csv .\testerFile.xlsx'.
At C:\Users\username\Desktop\scanner.ps1:69 char:1
+ Invoke-Expression 'C:\Users\username\Desktop\organizer.ps1' "$host ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Invoke-Expression], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeExpressionCommand
When you write this:
& '.\organizer.ps1' "-csvFile $hostfile -outputPath $outFile "
you are passing a single parameter to the script (one quoted string). That's not what you want.
This is what you need:
$hostfile = "C:\Users\username\Desktop\csvfile_test.csv"
$outFile = ".\testerFile.xlsx"
.\organizer.ps1 -csvFile $hostfile -outputPath $outFile
First, you don't need the & (invocation) operator because your command name (the organizer.ps1 script in the current location, in this example) doesn't contain spaces. (You can add it if you want, but it's unnecessary in this scenario.)
Second, the -csvFile and -outputPath parameters each require a string.

Errors when opening Nuget Package Manage Console

Whenever I open the package manager console in new VS 2017 session, it shows the below two error messages, and the for all intents and purposes operates normally. At least for vanilla commands like Install-Package.
Join-Path : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'ChildPath'. Specified method is not supported.
At C:\Dev\.NET\Projects\AcmeSoft\Code\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\tools\init.ps1:13 char:57
+ ... rPackageDirectory = Join-Path $packageDirectory $compilerPackage.Name
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Join-Path], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.JoinPathCommand
and
Join-Path : Cannot bind argument to parameter 'Path' because it is null.
At C:\Dev\.NET\Projects\AcmeSoft\Code\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\tools\init.ps1:14 char:44
+ ... erPackageToolsDirectory = Join-Path $compilerPackageDirectory 'tools'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Join-Path], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.JoinPathCommand
The offending line for the first is:
$compilerPackageDirectory = Join-Path $packageDirectory $compilerPackage.Name
with the error at $compilerPackage.Name (i.e. "char:57")
The offending line for the second is:
$compilerPackageToolsDirectory = Join-Path $compilerPackageDirectory 'tools'
with the error at $compilerPackageDirectory 'tools'.
Can anyone with more Nuget and or PowerShell skills than me explain why this is happening, and how I can fix it, please?

Showing error while adding element in List[int] in powershell?

$sumList= New-Object System.Collections.Generic.List[int]
$eventList = New-Object System.Collections.Generic.List[string]
$preSumList= New-Object System.Collections.Generic.List[int]
$threadInitDelay = [int]$commaSplit[++$eventIndex].Split(':')[1].Trim()
$preProcessTime = [int]$commaSplit[++$eventIndex].Split(':')[1].Trim()+[int]$commaSplit[++$eventIndex].Split(':')[1].Trim()+$commaSplit[[int]++$eventIndex].Split(':')[1].Trim()
$respTime = [int]$commaSplit[++$eventIndex].Split(':')[1].Trim();
$index =$eventList.FindIndex({param([string]$s) return $s -like 'hi'})
if($index -eq -1){
$eventList.Add($eventName)
$sumList.Add($threadInitDelay)
$respSumList.Add($respTime)
Getting this error:
Method invocation failed because [System.Int32[]] doesn't contain a method named 'Add'.
At D:\Powercel\PowershellPractice.ps1:151 char:19
+ $sumList.Add <<<< ($threadInitDelay)
+ CategoryInfo : InvalidOperation: (Add:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Method invocation failed because [System.Int32[]] doesn't contain a method named 'Add'.
At D:\Powercel\PowershellPractice.ps1:152 char:23
+ $respSumList.Add <<<< ($respTime)
+ CategoryInfo : InvalidOperation: (Add:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Method invocation failed because [System.Int32[]] doesn't contain a method named 'Add'.
At D:\Powercel\PowershellPractice.ps1:153 char:23
+ $respMaxTime.Add <<<< ($respTime)
+ CategoryInfo : InvalidOperation: (Add:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Method invocation failed because [System.Int32[]] doesn't contain a method named 'Add'.
At D:\Powercel\PowershellPractice.ps1:155 char:19
+ $minTime.Add <<<< ($threadInitDelay)
+ CategoryInfo : InvalidOperation: (Add:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Could you please help me out?
A possible scenario is that you were testing and actually casted those variables like the error states. The error is not wrong. Those variables are not the list types that you have in your code. I can almost reproduce this issue:
PS M:\Scripts\Inno\Output> [int[]]$sumlist = 5,5
PS M:\Scripts\Inno\Output> $sumlist.GetType().Fullname
System.Int32[]
PS M:\Scripts\Inno\Output> $sumlist.Add(5)
Exception calling "Add" with "1" argument(s): "Collection was of a fixed size."
At line:1 char:1
+ $sumlist.Add(5)
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : NotSupportedException
PS M:\Scripts\Inno\Output> $sumlist = New-Object System.Collections.Generic.List[int]
While I didn't get the same error as you the point is the type of the variable didn't change even though I tried to recasted it. That is because of property of the variable explained in this answer by PetSerAl. Have a look at the command Get-Variable sumlist | ft Name,Attributes and you should see System.Management.Automation.ArgumentTypeConverterAttribute. Removing the variable and starting again I get your expected behavior.
PS M:\Scripts\Inno\Output> Remove-Variable sumlist
PS M:\Scripts\Inno\Output> $sumlist = New-Object System.Collections.Generic.List[int]
PS M:\Scripts\Inno\Output> $sumlist.Add(5)
PS M:\Scripts\Inno\Output> $sumlist.GetType().FullName
System.Collections.Generic.List`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]

PowerShell Access Denied only for Local user who is also Admin but not for domain user who is local admin

We are trying to setup a machine for PSRemoting using the following command
Set-PSSessionConfiguration -Name Microsoft.PowerShell -showSecurityDescriptorUI
for some reason this only works when we open the powershell in the context of a domain user who is a local administrator.
PS C:\Windows\system32> Set-PSSessionConfiguration -Name Microsoft.PowerShell -showSecurityDescriptorUI
Confirm
Are you sure you want to perform this action?
Performing operation "Set-PSSessionConfiguration" on Target "Name:
Microsoft.PowerShell".
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help
(default is "Y"):A
Access is denied.
At line:15 char:26
+ if ((!$pluginName) -or <<<< !(test-path "$pluginDir"))
+ CategoryInfo : InvalidOperation: (:) [], InvalidOperationExcept
ion
+ FullyQualifiedErrorId : WsManError
Join-Path : Access is denied.
At line:22 char:35
+ $pluginFileNamePath = Join-Path <<<< "$pluginDir" 'FileName'
+ CategoryInfo : NotSpecified: (:) [Join-Path], InvalidOperationE
xception
+ FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.Power
Shell.Commands.JoinPathCommand
Test-Path : Cannot bind argument to parameter 'Path' because it is an empty str
ing.
At line:23 char:19
+ if (!(test-path <<<< "$pluginFileNamePath"))
+ CategoryInfo : InvalidData: (:) [Test-Path], ParameterBindingVa
lidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAl
lowed,Microsoft.PowerShell.Commands.TestPathCommand
Get-Item : Cannot bind argument to parameter 'LiteralPath' because it is an emp
ty string.
At line:29 char:43
+ $pluginFileName = get-item -literalpath <<<< "$pluginFileNamePath"
+ CategoryInfo : InvalidData: (:) [Get-Item], ParameterBindingVal
idationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAl
lowed,Microsoft.PowerShell.Commands.GetItemCommand
Set-PSSessionConfiguration : Session Configuration "Microsoft.PowerShell" is no
t a PowerShell based shell.
At line:89 char:27
+ Set-PSSessionConfiguration <<<< $args[0] $args[1] $args[2] $args[3] $args[4]
$args[5] $args[6] $args[7] $args[8]
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorExcep
tion
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorExceptio
n,Set-PSSessionConfiguration
PS C:\Windows\system32>
it looks to me that there is something that is preventing access to the wsman:\localhost\plugin but can't understand how that can be fixed. This only happens in our test bed, but in our development environment we have no such issues.
Does any one have any clue as to what additional user access is for this command to work that an local administrator user may not have?
Here is an article that explains how to resolve this problem... basically to fix this you set LocalAccountTokenFilterPolicy to True in the registry.
http://www.shirmanov.com/2011/04/winrm-access-is-denied-on-local.html

Powershell: FCIV script error: "Cannot find path because it does not exist"

I am new to PowerShell, so I may have missed something simple. I am trying to run a file checksum for Start-PsFCIV, outlined here.
My attempt is below, where I have also tried excluding the -Path parameter, as well as using relative/absolute paths.
PS C:\Users\Lucas\Downloads> Start-PsFCIV -Path C:\Users\Lucas\Downloads\DXSDK_Jun10.exe -HashAlgorithm SHA1
Set-Location : Cannot find path 'C:\Users\Lucas\Downloads\DXSDK_Jun10.exe' because it does not exist.
At C:\Scripts\PsFCIV_2.5.ps1:227 char:3
+ Set-Location -LiteralPath $path
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\Users\Lucas\Downloads\DXSDK_Jun10.exe:String) [Set-Location], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand
Test-Path : Cannot bind argument to parameter 'LiteralPath' because it is an empty string.
At C:\Scripts\PsFCIV_2.5.ps1:280 char:32
+ if (!(Test-Path -LiteralPath $XML)) {return New-Object PsFCIV.FCIV}
+ ~~~~
+ CategoryInfo : InvalidData: (:) [Test-Path], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.TestPathCommand
__fromxml : Input XML file is not valid FCIV XML file.
At C:\Scripts\PsFCIV_2.5.ps1:511 char:9
+ $sum = __fromxml $xml
+ ~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,__fromxml
Exception setting "VerboseForegroundColor": "Cannot convert value "-1" to type "System.Windows.Media.Color". Error: "Invalid cast from 'System.ConsoleColor' to 'System.Windows.Media.Color'.""
At C:\Scripts\PsFCIV_2.5.ps1:607 char:4
+ $host.PrivateData.VerboseForegroundColor = $Host.UI.RawUI.ForegroundColor
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], SetValueInvocationException
+ FullyQualifiedErrorId : ExceptionWhenSetting
You cannot call a method on a null-valued expression.
At C:\Scripts\PsFCIV_2.5.ps1:612 char:4
+ $sum.FILE_ENTRY.Add($entry)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Exception setting "VerboseForegroundColor": "Cannot convert value "-1" to type "System.Windows.Media.Color". Error: "Invalid cast from 'System.ConsoleColor' to 'System.Windows.Media.Color'.""
At C:\Scripts\PsFCIV_2.5.ps1:607 char:4
+ $host.PrivateData.VerboseForegroundColor = $Host.UI.RawUI.ForegroundColor
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], SetValueInvocationException
+ FullyQualifiedErrorId : ExceptionWhenSetting
How can I get this command to work? I could not find any solutions or similar problems after ~15 min search.
The first exception you get is thrown by Set-Location cmdlet that for some reason is used in the Start-PsFCIV script. Set-Location expects a folder as its -LiteralPath argument but you pass it a file instead.
As per "Useful Examples" on the PsFCIV webpage the solution is to use -Include argument. Example:
Start-PsFCIV -Path C:\tmp -Include InstallPackage.msi -XML DB.XML -HashAlgorithm SHA512
# Checks only InstallPackage.msi file in C:\tmp folder by using SHA512 hash algorithm.