Wait-Debugger
Menghentikan skrip di debugger sebelum menjalankan pernyataan berikutnya dalam skrip.
Sintaks
Wait-Debugger []
Deskripsi
Menghentikan mesin eksekusi skrip PowerShell pada titik tersebut segera setelah Wait-Debugger
cmdlet dan menunggu debugger dilampirkan. Ini mirip dengan penggunaan Enable-RunspaceDebug -BreakAll
dalam sumber daya DSC tetapi berhenti pada titik tertentu dalam skrip.
Perhatian
Pastikan Anda menghapus Wait-Debugger
baris setelah selesai. Skrip yang sedang berjalan tampaknya digantung ketika dihentikan di Wait-Debugger
.
Contoh
Contoh 1: Sisipkan titik henti untuk penelusuran kesalahan
[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
}
}
Input
None
Anda tidak dapat menyalurkan objek ke cmdlet ini.
Output
None
Cmdlet ini tidak mengembalikan output.
Link Terkait
Saran dan Komentar
https://aka.ms/ContentUserFeedback.
Segera hadir: Sepanjang tahun 2024 kami akan menghentikan penggunaan GitHub Issues sebagai mekanisme umpan balik untuk konten dan menggantinya dengan sistem umpan balik baru. Untuk mengetahui informasi selengkapnya, lihat:Kirim dan lihat umpan balik untuk