[Solved] PowerShell New-CommandWrapper : Supply values for the following parameters

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.

I obtained the code for New-CommandWrapper from the OP (it is the same as provided by O’Reilly), placed it in file New-CommandWrapper.ps1, and dot source it in my profile.ps1.
Now when I open a new session I get

cmdlet New-CommandWrapper.ps1 at command pipeline position 1
Supply values for the following parameters:
Name:

Is this ok? If so, what should I enter? Or how do I fix this?
(I am certain the issue is quite simple).

Note: I couldn’t make PSColor work, and this is possibly worth a another question.
As mentioned in a comment, after importing the module, (almost?) any cmdlet outputs

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

EDIT:
With the modification suggested by Thomas, the problem changed.
Now I get the same Value cannot be null. error.
I would like to conclude that his suggestion is right, and I solved one of the many chained problems I had… but I cannot be sure.

Solution #1:

As mentioned in the comments, New-CommandWrapper is packaged as a script, rather than as a function, so you’ll need to edit the script file slightly if you want to dot-source it:

  1. Insert function New-CommandWrapper { at the very top of New-CommandWrapper.ps1
  2. Add an } on the very last line

Now you can dot-source it (from your profile if need be) and use the example given in the linked answer:

PS C:> . .path	oNew-CommandWrapper.ps1
PS C:> New-CommandWrapper Out-Default `
>>>    -Process {
>>>        if(($_ -is [System.IO.DirectoryInfo]) -or ($_ -is [System.IO.FileInfo]))
>>>        {if(-not ($notfirst)) {
>>>           Write-Host "    Directory: $(pwd)`n"           
>>>           Write-Host "Mode                LastWriteTime     Length Name"
>>>           Write-Host "----                -------------     ------ ----"
>>>           $notfirst=$true
>>>           }
>>>           if ($_ -is [System.IO.DirectoryInfo]) {
>>>           Write-host ("{0,-7} {1,25} {2,10} {3}" -f $_.mode, ([String]::Format("{0,10}  {1,8}", $_.LastWriteTime.ToString("d"), $_.LastWriteTime.ToString("t"))), $_.length, $_.name) -foregroundcolor "yellow" }
>>>           else {
>>>           Write-host ("{0,-7} {1,25} {2,10} {3}" -f $_.mode, ([String]::Format("{0,10}  {1,8}", $_.LastWriteTime.ToString("d"), $_.LastWriteTime.ToString("t"))), $_.length, $_.name) -foregroundcolor "green" }
>>>           $_ = $null
>>>        }
>>>} 

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.