Wait-Debugger
Stoppt ein Skript im Debugger, bevor die nächste Anweisung im Skript ausgeführt wird.
Syntax
Wait-Debugger []
Beschreibung
Beendet das PowerShell-Skriptausführungsmodul an der Stelle unmittelbar nach dem Wait-Debugger
Cmdlet und wartet auf das Anfügen eines Debuggers. Dies ähnelt der Verwendung Enable-RunspaceDebug -BreakAll
in einer DSC-Ressource, bricht jedoch an einem bestimmten Punkt im Skript auf.
Achtung
Stellen Sie sicher, dass Sie die Wait-Debugger
Zeilen entfernen, nachdem Sie fertig sind. Ein ausgeführtes Skript scheint hängen zu sein, wenn es an einem Wait-Debugger
.
Beispiele
Beispiel 1: Einfügen eines Haltepunkts für das Debuggen
[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
}
}
Eingaben
None
Sie können keine Objekte an dieses Cmdlet weiterleiten.
Ausgaben
None
Dieses Cmdlet gibt keine Ausgabe zurück.
Ähnliche Themen
Feedback
https://aka.ms/ContentUserFeedback.
Bald verfügbar: Im Laufe des Jahres 2024 werden wir GitHub-Issues stufenweise als Feedbackmechanismus für Inhalte abbauen und durch ein neues Feedbacksystem ersetzen. Weitere Informationen finden Sie unterFeedback senden und anzeigen für