Home > Software design >  Powershell: Cannot find a variable with the name 'AmsiContext'
Powershell: Cannot find a variable with the name 'AmsiContext'

Time:12-01

Summary

Using Vagrant with Virtualbox and Powershell 5.* I get a message while running any vagrant commands.

PS C:\Users\dharris\SparkleShare\vagrant-salt> vagrant up es-master
Vagrant failed to initialize at a very early stage:

The version of powershell currently installed on this host is less than
the required minimum version. Please upgrade the installed version of
powershell to the minimum required version and run the command again.

  Installed version: Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 'AmsiInitFailed'.Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 'AmsiInitFailed'.Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 'AmsiInitFailed'.Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 'AmsiInitFailed'.Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 'AmsiInitFailed'.Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 'AmsiInitFailed'.Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 'AmsiInitFailed'.Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 
'AmsiInitFailed'.
  Minimum required version: 3

I have tried updating Vagrant, Virtualbox, and Windows 10 to latest but issue persists. I have Downloaded and installed Powershell 7.2.0, but issue still persists.

Versions

  • Virtualbox: 6.1.30 r148432 (Qt5.6.2)
  • Vagrant: 2.2.19
  • Windows 10 Pro: 21H1 build 19043.1387
  • Powershell: 7.2.0

Debug info below:

PS C:\Users\dharris\SparkleShare\vagrant-salt> vagrant status --debug
 INFO global: Vagrant version: 2.2.19
 INFO global: Ruby version: 2.7.4
 INFO global: RubyGems version: 3.1.6
 INFO global: VAGRANT_EXECUTABLE="C:\\HashiCorp\\Vagrant\\embedded\\gems\\2.2.19\\gems\\vagrant-2.2.19\\bin\\vagrant"
 INFO global: VAGRANT_INSTALLER_EMBEDDED_DIR="C:\\HashiCorp\\Vagrant\\embedded"
 INFO global: VAGRANT_INSTALLER_ENV="1"
 INFO global: VAGRANT_INSTALLER_VERSION="2"
 INFO global: VAGRANT_LOG="debug"
 WARN global: resolv replacement has not been enabled!
DEBUG global: Loading core plugin: C:/HashiCorp/Vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/plugins/commands/autocomplete/plugin.rb
 INFO manager: Registered plugin: autocomplete command
DEBUG global: Loading core plugin: C:/HashiCorp/Vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/plugins/commands/box/plugin.rb
 INFO manager: Registered plugin: box command
DEBUG global: Loading core plugin: C:/HashiCorp/Vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/plugins/commands/cap/plugin.rb
 INFO manager: Registered plugin: cap command
DEBUG global: Loading core plugin: C:/HashiCorp/Vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/plugins/commands/cloud/plugin.rb
 INFO manager: Registered plugin: vagrant-cloud

... (Cut similar loading lines due to stackoverflow's body limit)

DEBUG global: Loading core plugin: C:/HashiCorp/Vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/plugins/synced_folders/nfs/plugin.rb
 INFO manager: Registered plugin: NFS synced folders
DEBUG global: Loading core plugin: C:/HashiCorp/Vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/plugins/synced_folders/rsync/plugin.rb
 INFO manager: Registered plugin: RSync synced folders
DEBUG global: Loading core plugin: C:/HashiCorp/Vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/plugins/synced_folders/smb/plugin.rb
 INFO manager: Registered plugin: SMB synced folders
 INFO vagrant: `vagrant` invoked: ["status", "--debug"]
DEBUG vagrant: Creating Vagrant environment
 INFO environment: Environment initialized (#<Vagrant::Environment:0x0000024f428c8c58>)
 INFO environment:   - cwd: C:/Users/dharris/SparkleShare/vagrant-salt
 INFO environment: Home path: C:/Users/dharris/.vagrant.d
DEBUG environment: Effective local data path: C:/Users/dharris/SparkleShare/vagrant-salt/.vagrant
 INFO environment: Local data path: C:/Users/dharris/SparkleShare/vagrant-salt/.vagrant
DEBUG environment: Creating: C:/Users/dharris/SparkleShare/vagrant-salt/.vagrant
DEBUG manager: Enabling localized plugins
 INFO manager: Plugins:
 INFO manager:   - vagrant-vbguest = [installed: 0.30.0 constraint: > 0]
DEBUG solution_file: new solution file instance plugin_file=C:/Users/dharris/SparkleShare/vagrant-salt/.vagrant/plugins.json solution_file=C:/Users/dharris/SparkleShare/vagrant-salt/.vagrant/bundler/local.sol   
DEBUG solution_file: reading solution file - C:/Users/dharris/SparkleShare/vagrant-salt/.vagrant/bundler/local.sol
DEBUG solution_file: solution validation check CHECKSUM acf0db25918a838e88442e6b0b4ae9290e70e78ed8c4f922188c13a886b0de24 <-> acf0db25918a838e88442e6b0b4ae9290e70e78ed8c4f922188c13a886b0de24 VERSION 2.2.19 <-> 2.2.19
DEBUG solution_file: loading solution dependency list
DEBUG solution_file: solution dependency list: [#<Gem::Resolver::DependencyRequest:0x0000024f42966598 @dependency=<Gem::Dependency type=:runtime name="log4r" requirements=">= 0">, @requester=nil>, #<Gem::Resolver::DependencyRequest:0x0000024f429662f0 @dependency=<Gem::Dependency type=:runtime name="concurrent-ruby" requirements="~> 1.0">, @requester=nil>, #<Gem::Resolver::DependencyRequest:0x0000024f429660c0 @dependency=<Gem::Dependency type=:runtime name="i18n" requirements=">= 0">, @requester=nil>, #<Gem::Resolver::DependencyRequest:0x0000024f42965c60 @dependency=<Gem::Dependency type=:runtime name="micromachine" requirements=">= 2, < 4">, @requester=nil>, #<Gem::Resolver::DependencyRequest:0x0000024f42965878 @dependency=<Gem::Dependency type=:runtime name="vagrant-vbguest" requirements="= 0.30.0">, @requester=nil>]
DEBUG bundler: solution file in use for init: <Vagrant::Bundler::SolutionFile:C:/Users/dharris/SparkleShare/vagrant-salt/.vagrant/plugins.json:C:/Users/dharris/SparkleShare/vagrant-salt/.vagrant/bundler/local.sol:valid>
DEBUG bundler: Generating new builtin set instance.
DEBUG bundler: Generating new plugin set instance. Skip gems - []
DEBUG bundler: Generating new plugin set instance. Skip gems - []
DEBUG bundler: loading cached solution set
DEBUG bundler: activating solution set
DEBUG bundler: Activating solution set: ["log4r-1.1.10", "concurrent-ruby-1.1.9", "i18n-1.8.11", "micromachine-3.0.0", "vagrant-vbguest-0.30.0"]
DEBUG bundler: Activating gem micromachine-3.0.0
DEBUG bundler: Activating gem vagrant-vbguest-0.30.0
 INFO manager: Loading plugins...
 INFO manager: Loading plugin `vagrant-vbguest` with default require: `vagrant-vbguest`
 INFO manager: Registered plugin: vagrant-vbguest
DEBUG manager: Successfully loaded plugin `vagrant-vbguest`.
DEBUG manager: Enabling globalized plugins
 INFO manager: Plugins:
 INFO manager:   - deep_merge = [installed: 1.2.1 constraint: > 0]
 INFO manager:   - vagrant-vbguest = [installed: 0.30.0 constraint: > 0]
DEBUG solution_file: new solution file instance plugin_file=C:/Users/dharris/.vagrant.d/plugins.json solution_file=C:/Users/dharris/SparkleShare/vagrant-salt/.vagrant/bundler/global.sol
DEBUG solution_file: reading solution file - C:/Users/dharris/SparkleShare/vagrant-salt/.vagrant/bundler/global.sol
DEBUG solution_file: solution validation check CHECKSUM 93daf05d7b66957da4fcfce1a1306b17d766fdfda4a897f8b1ad57958f5a8cec <-> 93daf05d7b66957da4fcfce1a1306b17d766fdfda4a897f8b1ad57958f5a8cec VERSION 2.2.19 <-> 2.2.19
DEBUG solution_file: loading solution dependency list
DEBUG solution_file: solution dependency list: [#<Gem::Resolver::DependencyRequest:0x0000024f425aa328 @dependency=<Gem::Dependency type=:runtime name="deep_merge" requirements="= 1.2.1">, @requester=nil>, #<Gem::Resolver::DependencyRequest:0x0000024f425aa0f8 @dependency=<Gem::Dependency type=:runtime name="log4r" requirements=">= 0">, @requester=nil>, #<Gem::Resolver::DependencyRequest:0x0000024f425a9e50 @dependency=<Gem::Dependency type=:runtime name="concurrent-ruby" requirements="~> 1.0">, @requester=nil>, #<Gem::Resolver::DependencyRequest:0x0000024f425a9bf8 @dependency=<Gem::Dependency type=:runtime name="i18n" requirements=">= 0">, @requester=nil>, #<Gem::Resolver::DependencyRequest:0x0000024f425a9720 @dependency=<Gem::Dependency type=:runtime name="micromachine" requirements=">= 2, < 4">, @requester=nil>, #<Gem::Resolver::DependencyRequest:0x0000024f425a9478 @dependency=<Gem::Dependency type=:runtime name="vagrant-vbguest" requirements="= 0.30.0">, @requester=nil>]
DEBUG bundler: solution file in use for init: <Vagrant::Bundler::SolutionFile:C:/Users/dharris/.vagrant.d/plugins.json:C:/Users/dharris/SparkleShare/vagrant-salt/.vagrant/bundler/global.sol:valid>
DEBUG bundler: Generating new builtin set instance.
DEBUG bundler: Generating new plugin set instance. Skip gems - []
DEBUG bundler: Generating new plugin set instance. Skip gems - []
DEBUG bundler: loading cached solution set
DEBUG bundler: activating solution set
DEBUG bundler: Activating solution set: ["deep_merge-1.2.1", "log4r-1.1.10", "concurrent-ruby-1.1.9", "i18n-1.8.11", "micromachine-3.0.0", "vagrant-vbguest-0.30.0"]
DEBUG bundler: Activating gem deep_merge-1.2.1
DEBUG bundler: Activating gem micromachine-3.0.0
DEBUG bundler: Activating gem vagrant-vbguest-0.30.0
 INFO manager: Loading plugins...
 INFO manager: Loading plugin `deep_merge` with default require: `deep_merge`
DEBUG manager: Successfully loaded plugin `deep_merge`.
 INFO manager: Loading plugin `vagrant-vbguest` with default require: `vagrant-vbguest`
DEBUG manager: Successfully loaded plugin `vagrant-vbguest`.
 INFO loader: Set :root = ["#<Pathname:C:/Users/dharris/SparkleShare/vagrant-salt/Vagrantfile>"]
DEBUG loader: Populating proc cache for #<Pathname:C:/Users/dharris/SparkleShare/vagrant-salt/Vagrantfile>
DEBUG loader: Load procs for pathname: C:/Users/dharris/SparkleShare/vagrant-salt/Vagrantfile
 INFO loader: Loading configuration in order: [:home, :root]
DEBUG loader: Loading from: root (evaluating)
DEBUG loader: Configuration loaded successfully, finalizing and returning
DEBUG push: finalizing
 INFO subprocess: Starting process: ["C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\/powershell.EXE", "-NoLogo", "-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-Command", "Write-Output $PSVersionTable.PSVersion.Major"]
 INFO subprocess: Command not in installer, restoring original environment...
DEBUG subprocess: Selecting on IO
DEBUG subprocess: stdout: 5
DEBUG subprocess: stderr: Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 'AmsiInitFailed'.Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 'AmsiInitFailed'.Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 'AmsiInitFailed'.Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 'AmsiInitFailed'.Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 'AmsiInitFailed'.Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 'AmsiInitFailed'.Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 'AmsiInitFailed'.Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the 
name 'AmsiInitFailed'.
DEBUG subprocess: Waiting for process to exit. Remaining to timeout: 28
DEBUG subprocess: Exit status: 0
ERROR vagrant: Vagrant experienced an error! Details:
ERROR vagrant: #<Vagrant::Errors::PowerShellInvalidVersion: The version of powershell currently installed on this host is less than
the required minimum version. Please upgrade the installed version of
powershell to the minimum required version and run the command again.

  Installed version: Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 'AmsiInitFailed'.Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 'AmsiInitFailed'.Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 'AmsiInitFailed'.Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 'AmsiInitFailed'.Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 'AmsiInitFailed'.Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 'AmsiInitFailed'.Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 'AmsiInitFailed'.Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 
'AmsiInitFailed'.
  Minimum required version: 3>
ERROR vagrant: The version of powershell currently installed on this host is less than
the required minimum version. Please upgrade the installed version of
powershell to the minimum required version and run the command again.

  Installed version: Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 'AmsiInitFailed'.Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 'AmsiInitFailed'.Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 'AmsiInitFailed'.Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 'AmsiInitFailed'.Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 'AmsiInitFailed'.Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 'AmsiInitFailed'.Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 'AmsiInitFailed'.Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 
'AmsiInitFailed'.
  Minimum required version: 3
ERROR vagrant: C:/HashiCorp/Vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/lib/vagrant/util/powershell.rb:213:in `validate_install!'
C:/HashiCorp/Vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/lib/vagrant/util/powershell.rb:113:in `execute_cmd'
C:/HashiCorp/Vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/lib/vagrant/util/platform.rb:82:in `block in windows_admin?'
C:/HashiCorp/Vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/lib/vagrant/util/platform.rb:84:in `windows_admin?'
C:/HashiCorp/Vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/plugins/providers/hyperv/provider.rb:20:in `usable?'
C:/HashiCorp/Vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/lib/vagrant/environment.rb:361:in `block in default_provider'
C:/HashiCorp/Vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/lib/vagrant/registry.rb:49:in `block in each'
C:/HashiCorp/Vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/lib/vagrant/registry.rb:48:in `each'
C:/HashiCorp/Vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/lib/vagrant/registry.rb:48:in `each'
C:/HashiCorp/Vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/lib/vagrant/environment.rb:347:in `default_provider'
C:/HashiCorp/Vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/lib/vagrant/environment.rb:944:in `guess_provider'
C:/HashiCorp/Vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/lib/vagrant/environment.rb:956:in `find_configured_plugins'
C:/HashiCorp/Vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/lib/vagrant/environment.rb:984:in `process_configured_plugins'
C:/HashiCorp/Vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/lib/vagrant/environment.rb:178:in `initialize'
C:/HashiCorp/Vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/bin/vagrant:194:in `new'
C:/HashiCorp/Vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/bin/vagrant:194:in `<main>'
Vagrant failed to initialize at a very early stage:

The version of powershell currently installed on this host is less than
the required minimum version. Please upgrade the installed version of
powershell to the minimum required version and run the command again.

  Installed version: Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 'AmsiInitFailed'.Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 'AmsiInitFailed'.Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 'AmsiInitFailed'.Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 'AmsiInitFailed'.Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 'AmsiInitFailed'.Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 'AmsiInitFailed'.Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 'AmsiInitFailed'.Cannot find a variable with the name 'AmsiContext'.Cannot find a variable with the name 
'AmsiInitFailed'.
  Minimum required version: 3

CodePudding user response:

I've been seeing this recently. Do you use SentinelOne? I have a feeling this is SentinelOne trying to detect AMSI bypasses in PowerShell scripts.

CodePudding user response:

SentinelOne just sent an email out that might fix your issue.

The following needs to be added as a policy override:

{
  "powershellProtection":false
}

Hopefully you can implement this and it resolved your issue.

  • Related