System Details Output
### VSCode version: 1.51.1 e5a624b788d92b8d34d1392e4c4d9789406efe8f x64
### VSCode extensions:
[email protected]
[email protected]
### PSES version: 2.3.0.0
### PowerShell version:
Name Value
---- -----
PSVersion 5.1.19041.610
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.610
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
PSScriptAnalyzer not works code when using PSUseCompatibleCmdlets rule only with with following.

Works when I run PSScriptAnalyzer from PowerShell Integrated Console via command Invoke-ScriptAnalyzer

PSScriptAnalyzerSettings.psd1
@{
Rules = @{
PSUseCompatibleCmdlets = @{
'compatibility' = @("desktop-2.0-windows")
}
PSUseCompatibleCommands = @{
# Turns the rule on
Enable = $true
# Lists the PowerShell platforms we want to check compatibility with
TargetProfiles = @(
'ubuntu_x64_18.04_7.0.0_x64_3.1.2_core'
)
}
}
}
I tested when ms-vscode.powershell-preview was enabled and ms-vscode.powershell disabled, and next time when ms-vscode.powershell-preview was disabled and ms-vscode.powershell enabled - same results
Script analysis should works.
Script analysis not works.
I sent the logs by e-mail to [email protected]
Topic: [Issue 3155] PSScriptAnalyzer is unavailable when using the specific PowerShell statement - logs
Same problem as issue 3090, but the old one has closed and the problem still exists
So it looks like the UseCompatibleCmdlets rule is returning a null extent for Get-ScheduledTask:

The actual issue lies here, in PSScriptAnalyzer.
There's not much we can do to repair what we're given in PSES, but we can skip over the result so that it doesn't crash the script analysis run.
This issue can actually be reproduced with just PSScriptAnalyzer itself:
$script = @'
New-ScheduledJobOption
$TaskName = "Adobe Acrobat Update Task"
$TaskPath = "\"
Write-Output "##[debug] Current task state is $((Get-ScheduledTask -TaskName $TaskName -TaskPath $TaskPath).State)"
'@
$settings = @{
Rules = @{
PSUseCompatibleCmdlets = @{
'compatibility' = @("desktop-2.0-windows")
}
PSUseCompatibleCommands = @{
# Turns the rule on
Enable = $true
# Lists the PowerShell platforms we want to check compatibility with
TargetProfiles = @(
'ubuntu_x64_18.04_7.0.0_x64_3.1.2_core'
)
}
}
}
Invoke-ScriptAnalyzer -ScriptDefinition $script -Settings $settings
@msl0 if you disable the PSUseCompatibleCmdlets rule, this will work again. I've also started a branch where we catch this error in the future, so we do what I describe above instead.
So as far as I understand in a future version of the extension, if a similar problem occurs, the specific rule will be skipped in order not to block the entire analysis, right?
Most helpful comment
So as far as I understand in a future version of the extension, if a similar problem occurs, the specific rule will be skipped in order not to block the entire analysis, right?