Wait-Debugger

Arrête un script dans le débogueur avant d’exécuter l’instruction suivante dans le script.

Syntax

Wait-Debugger []

Description

Arrête le moteur d’exécution du script PowerShell au point immédiatement après l’applet Wait-Debugger de commande et attend qu’un débogueur soit attaché. Cela est similaire à l’utilisation Enable-RunspaceDebug -BreakAll dans une ressource DSC, mais s’arrête à un point spécifique dans le script.

Attention

Veillez à supprimer les Wait-Debugger lignes une fois que vous avez terminé. Un script en cours d’exécution semble être suspendu lorsqu’il est arrêté à un Wait-Debugger.

Exemples

Exemple 1 : Insérer un point d’arrêt pour le débogage

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

Entrées

None

Vous ne pouvez pas diriger les objets vers cette applet de commande.

Sorties

None

Cette applet de commande ne retourne pas de sortie.