title: How do I provision a Windows guest using the Vagrant shell/path provisioner?
body: <p>I am trying to use Powershell to provision a Windows Vagrant machine.  I've verified that my script works on my local machine if I launch Powershell as an Administrator.  During the Vagrant provisioning process, the vagrant user cannot elevate and run the script.      </p>
  
  <p>I know powershell scripts are supported with Vagrant, so what needs to happen to use them for provisioning?  My initial thought is try to have the script to launch an new Administrator Powershell, but I feel there must be a better way.</p>
  
  <p>I'm trying to just download a file using <code>System.Net.WebClient</code> and using <code>msiexec</code> to install.</p>
  
  <p>Vagrantfile:</p>
  
  <pre><code># -*- mode: ruby -*-
  # vi: set ft=ruby :
  VAGRANTFILE_API_VERSION = "2"
  PROVISION_WIN7_SCRIPT = "provision_win7.ps1"
  
  Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
    config.vm.define "win7", primary: false do |win7|
    config.vm.provision "shell", :path =&gt; "#{PROVISION_WIN7_SCRIPT}"
    config.vm.box      = "win7"
    config.vm.hostname = "win7"
    config.vm.communicator = "winrm"
    config.vm.network :private_network, ip: "10.10.10.10"
    config.vm.box_url = "https://atlas.hashicorp.com/designerror/boxes/windows-7/versions/1.0/providers/virtualbox.box"   
      config.vm.provider :virtualbox do |vb|
        vb.gui = true
        vb.customize ["modifyvm", :id, "--memory", 1024]
        vb.customize ["modifyvm", :id, "--cpus", 1]
        vb.customize ["modifyvm", :id, "--vram", "32"]
        vb.customize ["modifyvm", :id, "--clipboard", "bidirectional"]
        vb.customize ["setextradata", "global", "GUI/SuppressMessages", "all" ]
    end
    end
  end
  </code></pre>
  
  <p>Edit:</p>
  
  <p>I tried this again today using what I was running at the time: Vagrant 1.6.3, Virtualbox 4.3.30. When I bring up my vagrant box, I do not see any error output:</p>
  
  <pre><code>Bringing machine 'win7' up with 'virtualbox' provider...
  ==&gt; win7: Importing base box 'designerror/windows-7'...
  ==&gt; win7: Matching MAC address for NAT networking...
  ==&gt; win7: Checking if box 'designerror/windows-7' is up to date...
  ==&gt; win7: Setting the name of the VM: vagrant_win7_1453859492744_23074
  ==&gt; win7: Clearing any previously set network interfaces...
  ==&gt; win7: Preparing network interfaces based on configuration...
      win7: Adapter 1: nat
      win7: Adapter 2: hostonly
  ==&gt; win7: Forwarding ports...
      win7: 3389 =&gt; 3389 (adapter 1)
      win7: 22 =&gt; 2222 (adapter 1)
      win7: 5985 =&gt; 55985 (adapter 1)
  ==&gt; win7: Running 'pre-boot' VM customizations...
  ==&gt; win7: Booting VM...
  ==&gt; win7: Waiting for machine to boot. This may take a few minutes...
  ==&gt; win7: Machine booted and ready!
  ==&gt; win7: Checking for guest additions in VM...
  ==&gt; win7: Setting hostname...
  ==&gt; win7: Configuring and enabling network interfaces...
  ==&gt; win7: Mounting shared folders...
      win7: /vagrant =&gt; /Users/dstark/Projects/itbestprac-pres/vagrant
  ==&gt; win7: Running provisioner: shell...
      win7: Running: c:\tmp\vagrant-shell.ps1
  </code></pre>
  
  <p>On my vagrant box under c:\tmp there's a <code>vagrant-shell.ps1</code> and <code>vagrant-elevated-shell.ps1</code> and if I manually execute the vagrant generated elevated shell ps script as the vagrant user it installs.  So, I think my script is ok.</p>
  
  <p>If I add the <code>config.winrm.username</code> and <code>config.winrm.password</code> I still am not able to elevate permissions necessary to run the script.  There's also nothing telling in the Event Viewer.</p>