Question

Recently I had to add an intermediate variable to a PowerShell script, otherwise the New-Item result would be part of the function result:

      # Put in local varible, otherwise we will return it as part of the function result
      $Local:logDirectory = New-Item -ItemType directory -Path $Local:logDir
      Write-Host "Created directory '$Local:logDir'"
  }
  return "$Local:logDir\$LogFileName"

While debugging this, I would have loved to be able to dump (Write-Host or something) the current bits that the function already has queued up to end in the pipeline upon function return.

So:

From within a PowerShell function, how to view the result that so far will be returned to the pipeline

Was it helpful?

Solution

Use PowerGUI (a powershell IDE), you will be able to insert breakpoints and inspect the runtime variables.

http://en.community.dell.com/techcenter/powergui/m/

You can also use piping to Out-Null, i.e:

New-Item -ItemType directory -Path $Local:logDir | Out-Null

to get rid of spurious output. Unfortunately you might have to go through your code line by line.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top