Wait-Debugger
Stoppar ett skript i felsökningsprogrammet innan du kör nästa instruktion i skriptet.
Syntax
Wait-Debugger []
Description
Stoppar PowerShell-skriptkörningsmotorn direkt efter cmdleten Wait-Debugger
och väntar på att ett felsökningsprogram ska kopplas. Detta liknar att använda Enable-RunspaceDebug -BreakAll
i en DSC-resurs men bryts vid en viss punkt i skriptet.
Varning
Se till att du tar bort raderna Wait-Debugger
när du är klar. Ett skript som körs verkar vara låst när det stoppas vid en Wait-Debugger
.
Exempel
Exempel 1: Infoga brytpunkt för felsökning
[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
}
}
Indata
None
Du kan inte skicka objekt till den här cmdleten.
Utdata
None
Den här cmdleten returnerar inga utdata.
Relaterade länkar
Samarbeta med oss på GitHub
Källan för det här innehållet finns på GitHub, där du även kan skapa och granska ärenden och pull-begäranden. Se vår deltagarguide för mer information.