We saw that adding CmdletBinding() and using the debug switch when calling the script shows us debug output. However, what if your function is not designed to support debugging or you are not using a function at all? What if you would like to step through each of the steps in the script?
Run the following script in Debug mode:
function New-File { param ( # The path to the file (or the name) [Parameter(Mandatory=$true, Position=0)] [string[]] $Path ) begin { Write-Debug "Entered the begin block." Write-Host "$(Get-Date)" } process { Write-Debug "Entered the process block." foreach ($Item in $Path) { Write-Debug "Iterating for item, $Item." New-Item -Path $Path -ItemType File } } end { ...