为什么 Windows 来宾配置在删除 WinRM 日志时失败?

Why does Windows guest provisioning fail when removing a WinRM log?

我不知道从哪里开始解决这个问题。我正在使用 modernIE\w7-ie8 框。我第一次启动它(vagrant up 从头开始​​),需要手动调整它才能让 Vagrant 连接:

之后,我有三个简短的 shell 规定语句:注册一些 DLL,安装 Chocolatey,并安装 Chocolatey 包。

流浪文件:

config.vm.provision "shell", inline: "regsvr32 foo/Foo.dll"
config.vm.provision "shell", inline: "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))"
config.vm.provision "shell", inline: "choco install foo -y"

输出:

PS> vagrant provision
==> default: Running provisioner: shell...
    default: Running: inline PowerShell script
==> default: Running provisioner: shell...
    default: Running: inline PowerShell script
==> default: Remove-Item : Cannot remove item C:\Windows\Temp\WinRM_Elevated_Shell.log: The
==> default: process cannot access the file 'C:\Windows\Temp\WinRM_Elevated_Shell.log' becau
==> default: se it is being used by another process.
==> default: At C:\tmp\vagrant-elevated-shell.ps1:19 char:6
==> default: +   del <<<<  $out_file
==> default:     + CategoryInfo          : WriteError: (C:\Windows\Temp\WinRM_Elevated_Shel
==> default:    l.log:FileInfo) [Remove-Item], IOException
==> default:     + FullyQualifiedErrorId : RemoveFileSystemItemIOError,Microsoft.PowerShell
==> default:    .Commands.RemoveItemCommand
The following WinRM command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

powershell -ExecutionPolicy Bypass -OutputFormat Text -file c:\tmp\vagrant-shell.ps1

Stdout from the command:



Stderr from the command:

Remove-Item : Cannot remove item C:\Windows\Temp\WinRM_Elevated_Shell.log: The
process cannot access the file 'C:\Windows\Temp\WinRM_Elevated_Shell.log' becau
se it is being used by another process.
At C:\tmp\vagrant-elevated-shell.ps1:19 char:6
+   del <<<<  $out_file
    + CategoryInfo          : WriteError: (C:\Windows\Temp\WinRM_Elevated_Shel
   l.log:FileInfo) [Remove-Item], IOException
    + FullyQualifiedErrorId : RemoveFileSystemItemIOError,Microsoft.PowerShell
   .Commands.RemoveItemCommand

我需要确认 heredoc 版本的行为:

config.vm.provision "shell", inline: <<-SCRIPT
  regsvr32 foo/Foo.dll
  iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
  choco install foo -y
SCRIPT

并将脚本缩减为任意 2 个命令,甚至只是 echos:

config.vm.provision "shell", inline: "echo %COMPUTERNAME%"
config.vm.provision "shell", inline: "echo %COMPUTERNAME%"

我认为 #3816 就是答案。它对我有用。将 privileged: false 添加到 provision 调用的末尾,应该这样做。

config.vm.provision "shell", inline: "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))", privileged: false