jabbera / my-vsts-tasks

20 stars 18 forks source link

Cannot find a variable with the name 'AmsiContext' #56

Open nitewulf opened 1 year ago

nitewulf commented 1 year ago

I'm trying to use this extension in one of my release pipelines and am getting an error message (title) and then this full error (below).

I'm thinking maybe it is the version of PowerShell on the server. I have this integrated into a release for a different server and it works without issue.

Server 2012 with PowerShell 5.1.14409.1029 - produces error Server 2019 with PowerShell 5.1.17763.2931 - works without issue

I have attempted to update the PowerShell version using the Windows Managment Framework: https://www.microsoft.com/en-us/download/details.aspx?id=54616 However, the server reports that the patch is already installed so I am unsure how to get the PowerShell versions to be equivalent to rule that out as an issue. I'm guessing the server version explains the patch and revision differences.

I was wondering if this error had ever come up before and there's maybe some other explanation for it.

Thanks, Scott

2023-01-18T14:38:43.6755286Z Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 'AmsiInitFailed' (Repeats dozens of times) 2023-01-18T14:38:43.7348522Z ##[error]Exit code 1 returned from process: file name 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe', arguments '-NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". ([scriptblock]::Create('if ([Console]::InputEncoding -is [Text.UTF8Encoding] -and [Console]::InputEncoding.GetPreamble().Length -ne 0) { [Console]::InputEncoding = New-Object Text.UTF8Encoding $false } if (!$PSHOME) { $null = Get-Item -LiteralPath ''variable:PSHOME'' } else { Import-Module -Name ([System.IO.Path]::Combine($PSHOME, ''Modules\Microsoft.PowerShell.Management\Microsoft.PowerShell.Management.psd1'')) ; Import-Module -Name ([System.IO.Path]::Combine($PSHOME, ''Modules\Microsoft.PowerShell.Utility\Microsoft.PowerShell.Utility.psd1'')) }')) 2>&1 | ForEach-Object { Write-Verbose $_.Exception.Message -Verbose } ; Import-Module -Name 'C:\azagent\A2_work_tasks\StopWindowsService_601cd43e-b65d-49b7-b118-091333bd5b9f\8.0.0\ps_modules\VstsTaskSdk\VstsTaskSdk.psd1' -ArgumentList @{ NonInteractive = $true } -ErrorAction Stop ; $VerbosePreference = 'SilentlyContinue' ; $DebugPreference = 'SilentlyContinue' ; Invoke-VstsTaskScript -ScriptBlock ([scriptblock]::Create('. ''C:\azagent\A2_work_tasks\StopWindowsService_601cd43e-b65d-49b7-b118-091333bd5b9f\8.0.0\StopWindowsService.ps1'''))"'.