Wait-Debugger
在脚本中运行下一个语句之前,停止调试器中的脚本。
语法
Wait-Debugger []
说明
在紧接 cmdlet 之后 Wait-Debugger
的某个时间点停止 PowerShell 脚本执行引擎,并等待附加调试器。 这类似于在 DSC 资源中使用 Enable-RunspaceDebug -BreakAll
,但在脚本中的特定点中断。
注意
请确保在完成后删除 Wait-Debugger
这些行。 当正在运行的脚本在 处 Wait-Debugger
停止时,该脚本似乎已挂起。
示例
示例 1:插入断点进行调试
[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
}
}
输入
None
不能通过管道将对象传递给此 cmdlet。
输出
None
此 cmdlet 不返回任何输出。