Wait-Debugger

Detiene un script en el depurador antes de ejecutar la siguiente instrucción en el script.

Syntax

Wait-Debugger []

Description

Detiene el motor de ejecución de scripts de PowerShell en el punto inmediatamente después del Wait-Debugger cmdlet y espera a que se adjunte un depurador. Esto es similar al uso Enable-RunspaceDebug -BreakAll en un recurso de DSC, pero se interrumpe en un punto específico del script.

Precaución

Asegúrese de quitar las Wait-Debugger líneas después de que haya terminado. Parece que un script en ejecución se bloquea cuando se detiene en .Wait-Debugger

Ejemplos

Ejemplo 1: Insertar punto de interrupción para la depuración

[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
    }
}

Entradas

None

No se pueden canalizar objetos a este cmdlet.

Salidas

None

Este cmdlet no devuelve ningún resultado.