Get-StackIndent.ps1

function Get-StackIndent
{
  <#
      .SYNOPSIS
      Return a string formated containing line numbre in the source code, function where the line resided
      .DESCRIPTION
      Return a string formated as below
      [ 132 DeleteTempAdminUser] Delete user
      
      The leading number are the line of code number that is executed (max. 9999)
      The following string is the calling function name
      the string length within [] is a maximum of 25 characters
      The string is padded with SPACE to match the indent level:
      MAIN => no SPACE
      FUNCTION => 1 SPACE
      SUBFUNCTION of FUNCTION => 2 SPACES
      .EXAMPLE
      Get-StackIndent
  #>

  
  $padding   =  25
  $Tab       =  " "
        
  $callStack =  Get-PSCallStack

  $s         =  $callStack.FunctionName
  $n         =  $callStack.ScriptLineNumber

  $st        =  "["
  if ($s -gt 2)
  {
    $sn =  "{0,4}" -f $n[2] 
    $st += $sn 
    $st += " "
    $st += $s[2]
  }

  $st        =  $st.padright($padding," ")
  $st        =  $st.substring(0,$padding)
    
  $st        += "]"
  for ($i = 1; $i -lt  $callStack.count; $i++)
  { 
    $st += $Tab
  }
  
  return $st
}