Megosztás a következőn keresztül:


Wait-Debugger

Leállítja a szkriptet a hibakeresőben, mielőtt a következő utasítást futtatja a szkriptben.

Syntax

Default (Alapértelmezett)

Wait-Debugger

Description

Leállítja a PowerShell-szkript végrehajtási motort közvetlenül a Wait-Debugger parancsmag után, és megvárja a hibakereső csatlakoztatását.

Figyelmeztetés

A művelet befejezése után távolítsa el a Wait-Debugger sorokat. Úgy tűnik, hogy egy futó szkript megakad, amikor leáll egy Wait-Debugger-esnél.

A PowerShell hibakereséséről további információt a about_Debuggerscímű témakörben talál.

Példák

1. példa: Töréspont beszúrása hibakereséshez

A fájl dbgtest.ps1Test-Conditionfüggvényt tartalmaz. A Wait-Debugger parancs be lett szúrva a függvénybe a szkript végrehajtásának ezen a ponton történő leállításához. A függvény futtatásakor a szkript a Wait-Debugger sornál áll meg, és beírja a parancssori hibakeresőt. A l parancs felsorolja a szkriptsorokat, és más hibakereső parancsokkal is megvizsgálhatja a szkript állapotát.

function Test-Condition {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory)]
        [string]$Name,
        [string]$Message = "Hello, $Name!"
    )

    if ($Name -eq $Env:USERNAME) {
        Write-Output "$Message"
    } else {
        # Remove after debugging
        Wait-Debugger

        Write-Output "$Name is not the current user."
    }
}
PS D:\> Test-Condition Fred
Entering debug mode. Use h or ? for help.

At D:\temp\test\dbgtest.ps1:13 char:9
+         Wait-Debugger
+         ~~~~~~~~~~~~~
[DBG]: PS D:\>> l

    8:
    9:      if ($Name -eq $Env:USERNAME) {
   10:          Write-Output "$Message"
   11:      } else {
   12:          # Remove after debugging
   13:*         Wait-Debugger
   14:
   15:          Write-Output "$Name is not the current user."
   16:      }
   17:  }

[DBG]: PS D:\>> $Env:USERNAME
User01
[DBG]: PS D:\>> exit
PS D:\>

Figyelje meg, hogy a l kimenete azt mutatja, hogy a szkript végrehajtása le van állítva a Wait-Debugger-nál a 13. sorban.

2. példa: Töréspont beszúrása DSC-erőforrás hibakereséséhez

Ebben a példában a Wait-Debugger parancs be lett szúrva egy DSC-erőforrás CopyFile metódusában. Ez hasonló a Enable-RunspaceDebug -BreakAll DSC-erőforrásban való használatához, de a szkript egy adott pontján megszakad.

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

Bevitelek

None

Ehhez a parancsmaghoz nem lehet objektumokat csövezni.

Kimenetek

None

Ez a parancsmag nem ad vissza kimenetet.