PowerShell debug execution

為{幸葍}努か 提交于 2021-02-10 22:11:41

问题


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.

来源:https://stackoverflow.com/questions/63013113/powershell-debug-execution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!