问题
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:
I added Set-PSDebug -Trace 2 -Strict at the top of my
profile.ps1
.Enabled line
Import-Module PSColor
inprofile.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:
- I cannot infer from here the complete chain of commands starting from my
cd ...
- 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:
- Use
New-CommandWrapper
, as advocated in the OP and the answer by Jon Z. - 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