Debug-Job :The job cannot be debugged because the

2019-05-30 03:43发布

问题:

I created a sample powershell project with a Script.ps1 file and a Modules\Script1\Script1.psm1 file.

the module file..

# Script1.psm1
function Get-Greeting{
    Start-Sleep -Seconds 10
    Write-Host "hello from foo";
}

and the script file..

# Script1.ps1
if(-not(Get-Module -Name "Script1")){
    Import-Module .\Modules\Script1
}
if(Get-Module -Name "Script1"){
    Remove-Module Script1;
    Import-Module .\Modules\Script1;
}

Get-Greeting # output: hello from foo
$ajob = Start-Job -ScriptBlock {
    Get-Greeting
} -InitializationScript {

    if(-not(Get-Module -Name "Script1")){
        Import-Module 'C:\Users\suyashs\Documents\Visual Studio 2015\Projects\Playground\PowerShellProject2\PowerShellProject2\Modules\Script1'
    }
    if(Get-Module -Name "Script1"){
        Remove-Module Script1;
        Import-Module 'C:\Users\suyashs\Documents\Visual Studio 2015\Projects\Playground\PowerShellProject2\PowerShellProject2\Modules\Script1'
    }
} 

Debug-Job -Job $ajob

Error appears at last line Debug-Job -Job $ajob

[ERROR] Debug-Job : The job cannot be debugged because the host debugger mode is set to None or Default. The host debugger mode must be [ERROR] LocalScript and/or RemoteSript

What i want is that the breakpoint inside my Get-Greeting method gets hit.

I tried searching on the internet but failed to find a solution.

I am using Powershell ISE, Visual Studio 2015 powershell project. Current Powershell version is 5.0

Normal debugging works fine, but as soon as i start some async/multithreaded debugging i.e. using Start-Job i dont see any breakpoint getting hit.

Any help is appreciated.