1

Trying to use module PSColor, I get the error

Value cannot be null.
Parameter name: command
En línea: 39 Carácter: 9
+         $steppablePipeline.Begin($PSCmdlet)
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`

as mentioned in PowerShell New-CommandWrapper : Supply values for the following parameters

How can I trace execution of commands, to find the culprit and fix the problem?

What I tried:

  1. I added Set-PSDebug -Trace 2 -Strict at the top of my profile.ps1.

  2. Enabled line Import-Module PSColor in profile.ps1 (method 2 in question PowerShell New-CommandWrapper : Supply values for the following parameters and the most voted answer in Powershell: Properly coloring Get-Childitem output once and for all).

Now during startup I get a lot of debugging info. The output I get with my first command is

> cd .\utils\
DEBUG:    7+  >>>> {
DEBUG:     ! CALL function '<ScriptBlock><Begin>'
DEBUG:   13+          >>>> $foreachObject = $executionContext.InvokeCommand.GetCmdlet(
DEBUG:     ! SET $foreachObject = 'ForEach-Object'.
DEBUG:   16+          >>>> $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand(
DEBUG:     ! SET $wrappedCmd = 'Out-Default-01e1d80299c048d787db8ef5fe8bb78c'.
DEBUG:   22+          >>>> $targetParameters = @{}
DEBUG:     ! SET $targetParameters = 'System.Collections.Hashtable'.
DEBUG:   23+          >>>> $PSBoundParameters.GetEnumerator() |
DEBUG:   32+          >>>> $newPipeline = { & $wrappedCmd @targetParameters }
DEBUG:     ! SET $newPipeline = ' & $wrappedCmd @targetParameters '.
DEBUG:   33+          >>>> $finalPipeline = $newPipeline.ToString()
DEBUG:     ! SET $finalPipeline = ' & $wrappedCmd @targetParameters '.
DEBUG:   37+          >>>> $steppablePipeline = [ScriptBlock]::Create(
DEBUG:     ! SET $steppablePipeline = 'System.Management.Automation.SteppablePipel...'.
DEBUG:   39+          >>>> $steppablePipeline.Begin($PSCmdlet)
DEBUG:   41+          >>>> throw
Value cannot be null.
Parameter name: command
En línea: 39 Carácter: 9
+         $steppablePipeline.Begin($PSCmdlet)
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

But:

  1. I cannot infer from here the complete chain of commands starting from my cd ...
  2. File names are not shown.

So I cannot progress any further. The fact that I am a novice in PS certainly plays a significant role here.


Motivation for the question:

I mean to colorize the output of ls. I checked Powershell: Properly coloring Get-Childitem output once and for all.

The two options appear to be:

  1. Use New-CommandWrapper, as advocated in the OP and the answer by Jon Z.
  2. Use module PSColor.

Trying both options, I end up in an alley with the error above.


Related:

https://security.stackexchange.com/questions/180133/how-can-i-track-executed-powershell-commands-within-a-network . I was helped by this.

  • This is not an answer for the question, but I found the culprit for all the pain: I had added at the top of my `profile.ps1` the code suggested at the top of [this answer](https://stackoverflow.com/a/62838107/2707864). It worked mostly ok. But in some cases, by "interfering" with other commands, it was producing the `Value cannot be null.` error. Moreover, if I added that code below the scripts for colorizing `dir` output, it did not produce an error upon `dir`, but output was simply white. – sancho.s ReinstateMonicaCellio Jul 26 '20 at 08:17

0 Answers0