PoshCode Archive  Artifact [04340aab92]

Artifact 04340aab92df70e8531c2aebb7edff8896a251d8bdd8edf5f216e5e1dcee0e0c:

  • File Get-Scope.ps1 — part of check-in [ccfa44e0cd] at 2018-06-10 13:13:32 on branch trunk — Get PowerShell numbered scope in anytime!!! (user: ingted size: 746)

# encoding: ascii
# api: powershell
# title: Get-Scope
# description: Get PowerShell numbered scope in anytime!!!
# version: 0.1
# type: function
# author: ingted
# license: CC0
# function: Get-Scope
# x-poshcode-id: 2636
# x-archived: 2011-04-29T00:05:30
# x-published: 2011-04-26T23:12:00
#
#
function Get-Scope{
    $rtnScope = 0
    $global:scope = $false
    $scope = $true
    while($($ErrorActionPreference = "silentlycontinue"; switch((get-Variable -Name scope -Scope $rtnScope).value){$null{$true} $true{$true} $false{$ErrorActionPreference = "continue"; return ($rtnScope - 1)}})){
        $rtnScope++
    }
}

Example.

function gg{
    Get-Scope
}; 

function iii{
    gg
}; 

iii    ==> result is 2