{"action":"opened","issue":{"url":"https://api.github.com/repos/hashicorp/vagrant/issues/9138","repository_url":"https://api.github.com/repos/hashicorp/vagrant","labels_url":"https://api.github.com/repos/hashicorp/vagrant/issues/9138/labels{/name}","comments_url":"https://api.github.com/repos/hashicorp/vagrant/issues/9138/comments","events_url":"https://api.github.com/repos/hashicorp/vagrant/issues/9138/events","html_url":"https://github.com/hashicorp/vagrant/issues/9138","id":271112682,"number":9138,"title":"macOS, Vagrant, VirtualBox, shell provider powershell","user":{"login":"basictheprogram","id":6723257,"avatar_url":"https://avatars2.githubusercontent.com/u/6723257?v=4","gravatar_id":"","url":"https://api.github.com/users/basictheprogram","html_url":"https://github.com/basictheprogram","followers_url":"https://api.github.com/users/basictheprogram/followers","following_url":"https://api.github.com/users/basictheprogram/following{/other_user}","gists_url":"https://api.github.com/users/basictheprogram/gists{/gist_id}","starred_url":"https://api.github.com/users/basictheprogram/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/basictheprogram/subscriptions","organizations_url":"https://api.github.com/users/basictheprogram/orgs","repos_url":"https://api.github.com/users/basictheprogram/repos","events_url":"https://api.github.com/users/basictheprogram/events{/privacy}","received_events_url":"https://api.github.com/users/basictheprogram/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-11-03T20:40:54Z","updated_at":"2017-11-03T20:40:54Z","closed_at":null,"author_association":"NONE","body":"### Vagrant version\r\n$ vagrant -v\r\nVagrant 2.0.0\r\n\r\n### Host operating system\r\nmacOS 10.12.6\r\n\r\n### Guest operating system\r\nWindows Server 2016\r\n\r\n### Vagrantfile\r\n```ruby\r\n# Vagrant File (Vagrantfile)\r\n# http://docs.vagrantup.com/v2/vagrantfile/index.html\r\n\r\n# Windows guests can't even be used with Vagrant versions less than 1.3.5.\r\nVagrant.require_version \">= 1.3.5\"\r\nif Vagrant::VERSION < '1.6.0'\r\n  # Vagrant versions less than 1.6.x do not have a built-in way to\r\n  # communicate with Windows guest images.For versions less than 1.6.x\r\n  # the vagrant-windows plugin is required.\r\n  Vagrant.require_plugin \"vagrant-windows\"\r\nend\r\n\r\n# http://docs.vagrantup.com/v2/vagrantfile/machine_settings.html\r\nVagrant.configure(\"2\") do |config|\r\n  # This setting will download the atlas box at\r\n  # https://atlas.hashicorp.com/ferventcoder/boxes/win2012r2-x64-nocm\r\n  config.vm.box = \"BasicTheProgram/windows_2016\"\r\n\r\n  # http://docs.vagrantup.com/v2/providers/configuration.html\r\n  # http://docs.vagrantup.com/v2/virtualbox/configuration.html\r\n  config.vm.provider :virtualbox do |v, override|\r\n    # Show the GUI\r\n    v.gui = true\r\n    # 4GB RAM\r\n    v.customize [\"modifyvm\", :id, \"--memory\", \"4096\"]\r\n    # 2 CPUs\r\n    v.customize [\"modifyvm\", :id, \"--cpus\", \"2\"]\r\n    # Video RAM is 32 MB\r\n    v.customize [\"modifyvm\", :id, \"--vram\", 32]\r\n    # For better DNS resolution\r\n    v.customize [\"modifyvm\", :id, \"--natdnshostresolver1\", \"on\"]\r\n    # No audio\r\n    v.customize [\"modifyvm\", :id, \"--audio\", \"none\"]\r\n    # Clipboard enabled\r\n    v.customize [\"modifyvm\", :id, \"--clipboard\", \"bidirectional\"]\r\n    v.customize [\"modifyvm\", :id, \"--draganddrop\", \"hosttoguest\"]\r\n    # For performance\r\n    v.customize [\"modifyvm\", :id, \"--usb\", \"off\"]\r\n    # Huge performance gain here\r\n    v.linked_clone = true if Vagrant::VERSION >= '1.8.0'\r\n  end\r\n\r\n  # https://www.vagrantup.com/docs/hyperv/configuration.html\r\n  # https://technet.microsoft.com/en-us/library/dn798297(v=ws.11).aspx\r\n  config.vm.provider :hyperv do |v, override|\r\n    # 4GB RAM\r\n    v.memory = 4096\r\n    # 2 CPUs\r\n    v.cpus = 2\r\n    # The time in seconds to wait for the virtual machine to report an IP address\r\n    v.ip_address_timeout = 130\r\n    # Use differencing disk instead of cloning whole VHD\r\n    v.differencing_disk = true\r\n    v.vm_integration_services = {\r\n      guest_service_interface: true,\r\n      heartbeat: true,\r\n      key_value_pair_exchange: true,\r\n      shutdown: true,\r\n      time_synchronization: true,\r\n      vss: true\r\n  }\r\n  end\r\n\r\n  # timeout of waiting for image to stop running - may be a deprecated setting\r\n  config.windows.halt_timeout = 20\r\n  # username/password for accessing the image\r\n  config.winrm.username = \"vagrant\"\r\n  config.winrm.password = \"vagrant\"\r\n  # explicitly tell Vagrant the guest is Windows\r\n  config.vm.guest = :windows\r\n\r\n  if Vagrant::VERSION >= '1.6.0'\r\n    # If we are on greater than v1.6.x, we are using the built-in version\r\n    # of communicating with Windows. For versions less than 1.6 the\r\n    # `vagrant-windows` plugin would need to be installed and uses monkey\r\n    # patching to override the communicator.\r\n    config.vm.communicator = \"winrm\"\r\n  end\r\n\r\n  # Synced folders - http://docs.vagrantup.com/v2/synced-folders/\r\n  # A synced folder is a fancy term for shared folders - it takes a folder on\r\n  # the host and shares it with the guest (vagrant) image. The entire folder\r\n  # where the Vagrantfile is located is always shared as `c:\\vagrant` (the\r\n  # naming of this directory being `vagrant` is just a coincedence).\r\n  # Share `packages` directory as `C:\\packages`\r\n  config.vm.synced_folder \"packages\", \"/packages\"\r\n  config.vm.synced_folder \"/Users/tanner/projects/\", \"/projects\"\r\n\r\n  #config.vm.synced_folder \"temp\", \"/Users/vagrant/AppData/Local/Temp/chocolatey\"\r\n  # not recommended for sharing, it may have issues with `vagrant sandbox rollback`\r\n  #config.vm.synced_folder \"chocolatey\", \"/ProgramData/chocolatey\"\r\n\r\n  # Port forward WinRM / RDP\r\n  # Vagrant 1.9.3 - if you run into Errno::EADDRNOTAVAIL (https://github.com/mitchellh/vagrant/issues/8395),\r\n  #  add host_ip: \"127.0.0.1\" for it to work\r\n  config.vm.network :forwarded_port, guest: 5985, host: 5985, id: \"winrm\", auto_correct: true #, host_ip: \"127.0.0.1\"\r\n  config.vm.network :forwarded_port, guest: 3389, host: 3389, id: \"rdp\", auto_correct: true #, host_ip: \"127.0.0.1\"\r\n  # Port forward SSH (ssh is forwarded by default in most versions of Vagrant,\r\n  # but be sure). This is not necessary if you are not using SSH, but it doesn't\r\n  # hurt anything to have it\r\n  config.vm.network :forwarded_port, guest: 22, host: 2222, id: \"ssh\", auto_correct: true #, host_ip: \"127.0.0.1\"\r\n\r\n  # Provisioners - http://docs.vagrantup.com/v2/provisioning/\r\n  # In this specific vagrant usage, we are using the shell provisioner\r\n  # http://docs.vagrantup.com/v2/provisioning/shell.html\r\n  if Vagrant::VERSION < '1.8.0'\r\n    config.vm.provision :shell, :path => \"shell/PrepareWindows.ps1\"\r\n    config.vm.provision :shell, :path => \"shell/InstallNet4.ps1\"\r\n    config.vm.provision :shell, :path => \"shell/InstallChocolatey.ps1\"\r\n    config.vm.provision :shell, :path => \"shell/NotifyGuiAppsOfEnvironmentChanges.ps1\"\r\n  else\r\n    config.vm.provision :shell, :path => \"shell/PrepareWindows.ps1\", :powershell_elevated_interactive => true\r\n    config.vm.provision :shell, :path => \"shell/InstallNet4.ps1\", :powershell_elevated_interactive => true\r\n    config.vm.provision :shell, :path => \"shell/InstallChocolatey.ps1\", :powershell_elevated_interactive => true\r\n    config.vm.provision :shell, :path => \"shell/NotifyGuiAppsOfEnvironmentChanges.ps1\", :powershell_elevated_interactive => true\r\n    config.vm.provision :shell, :path => \"shell/InstallToolchain.ps1\", :powershell_elevated_interactive => true\r\n  end\r\n\r\n$packageTestScript = <<SCRIPT\r\nsetx.exe trigger 1  # run arbitrary win32 application so LASTEXITCODE is 0\r\n$ErrorActionPreference = \"Stop\"\r\n$env:PATH +=\";$($env:SystemDrive)\\\\ProgramData\\\\chocolatey\\\\bin\"\r\n# https://github.com/chocolatey/choco/issues/512\r\n$validExitCodes = @(0, 1605, 1614, 1641, 3010)\r\n\r\nWrite-Output \"Testing package if a line is uncommented.\"\r\n# THIS IS WHAT YOU CHANGE\r\n# - uncomment one of the two and edit it appropriately\r\n# - See the README for details\r\n#choco.exe install -fdvy INSERT_NAME --version INSERT_VERSION  --allow-downgrade\r\n#choco.exe install -fdvy INSERT_NAME  --allow-downgrade --source \"'c:\\\\packages;http://chocolatey.org/api/v2/'\"\r\n\r\n$exitCode = $LASTEXITCODE\r\n\r\nWrite-Host \"Exit code was $exitCode\"\r\nif ($validExitCodes -contains $exitCode) {\r\n  Exit 0\r\n}\r\n\r\nExit $exitCode\r\nSCRIPT\r\n\r\n  if Vagrant::VERSION < '1.8.0'\r\n    config.vm.provision :shell, :inline => $packageTestScript\r\n  else\r\n    config.vm.provision :shell, :inline => $packageTestScript, :powershell_elevated_interactive => true\r\n  end\r\nend\r\n```\r\n\r\n### Debug output\r\nhttps://gist.github.com/basictheprogram/9cb025b9c6f3f78a5b10132130c21883\r\n\r\n### Expected behavior\r\nThe shell provisions should execute and not error out.\r\n\r\n### Actual behavior\r\n$ vagrant  up\r\n==> default: Checking if box 'BasicTheProgram/windows_2016' is up to date...\r\n==> default: Running provisioner: shell...\r\n    default: Running: shell/PrepareWindows.ps1 as c:\\tmp\\vagrant-shell.ps1\r\n==> default: (10,8):UserId:\r\n==> default: At line:72 char:1\r\n==> default: + $folder.RegisterTaskDefinition($task_name, $task, 6, $username, $pass ...\r\n==> default: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n==> default:     + CategoryInfo          : OperationStopped: (:) [], ArgumentException\r\n==> default:     + FullyQualifiedErrorId : System.ArgumentException\r\n==> default: The system cannot find the file specified. (Exception from HRESULT: 0x80070002)\r\n==> default: At line:74 char:1\r\n==> default: + $registered_task = $folder.GetTask(\"\\$task_name\")\r\n==> default: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n==> default:     + CategoryInfo          : OperationStopped: (:) [], FileNotFoundException\r\n==> default:     + FullyQualifiedErrorId : System.IO.FileNotFoundException\r\n==> default: You cannot call a method on a null-valued expression.\r\n==> default: At line:75 char:1\r\n==> default: + $registered_task.Run($null) | Out-Null\r\n==> default: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n==> default:     + CategoryInfo          : InvalidOperation: (:) [], RuntimeException\r\n==> default:     + FullyQualifiedErrorId : InvokeMethodOnNull\r\n\r\n"}}
{"actor":{"display_login":"basictheprogram"}}