Share via


Wait-Debugger

스크립트에서 다음 문을 실행하기 전에 디버거에서 스크립트를 중지합니다.

Syntax

Wait-Debugger []

Description

cmdlet 바로 뒤의 지점에서 PowerShell 스크립트 실행 엔진을 Wait-Debugger 중지하고 디버거가 연결될 때까지 기다립니다. 이는 DSC 리소스에서 사용하는 Enable-RunspaceDebug -BreakAll 것과 비슷하지만 스크립트의 특정 지점에서 중단됩니다.

주의

작업을 완료한 Wait-Debugger 후 줄을 제거해야 합니다. 실행 중인 스크립트는 에서 Wait-Debugger중지될 때 중단된 것처럼 보입니다.

예제

예제 1: 디버깅을 위한 중단점 삽입

[DscResource()]
class FileResource
{
    [DscProperty(Key)]
    [string] $Path

    [DscProperty(Mandatory)]
    [Ensure] $Ensure

    [DscProperty(Mandatory)]
    [string] $SourcePath

    [DscProperty(NotConfigurable)]
    [Nullable[datetime]] $CreationTime


    [void] Set()
    {
        $fileExists = $this.TestFilePath($this.Path)
        if ($this.ensure -eq [Ensure]::Present)
        {
            if (! $fileExists)
            {
               $this.CopyFile()
            }
        }
        else
        {
            if ($fileExists)
            {
                Write-Verbose -Message "Deleting the file $($this.Path)"
                Remove-Item -LiteralPath $this.Path -Force
            }
        }
    }

    [bool] Test()
    {
        $present = Test-Path -LiteralPath $this.Path

        if ($this.Ensure -eq [Ensure]::Present)
        {
            return $present
        }
        else
        {
            return (! $present)
        }
    }

    [FileResource] Get()
    {
        $present = Test-Path -Path $this.Path

        if ($present)
        {
            $file = Get-ChildItem -LiteralPath $this.Path
            $this.CreationTime = $file.CreationTime
            $this.Ensure = [Ensure]::Present
        }
        else
        {
            $this.CreationTime = $null
            $this.Ensure = [Ensure]::Absent
        }

        return $this
    }

    [void] CopyFile()
    {
        # Testing only - Remove before deployment!
        Wait-Debugger

        if (! (Test-Path -LiteralPath $this.SourcePath))
        {
            throw "SourcePath $($this.SourcePath) is not found."
        }

        if (Test-Path -LiteralPath $this.Path -PathType Container)
        {
            throw "Path $($this.Path) is a directory path"
        }

        Write-Verbose "Copying $($this.SourcePath) to $($this.Path)"

        Copy-Item -LiteralPath $this.SourcePath -Destination $this.Path -Force
    }
}

입력

None

개체를 이 cmdlet으로 파이프할 수 없습니다.

출력

None

이 cmdlet은 출력을 반환하지 않습니다.