为什么在删除WinRM日志时Windows客户机配置失败?

时间:2016-01-20 18:51:49

标签: windows powershell vagrant winrm

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

  • 通过启动恢复/修复对话框继续/取消
  • 将网络类型从“公共”更改为“工作/主页”

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

Vagrantfile:

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个命令,即使只是echo s:

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

1 个答案:

答案 0 :(得分:3)

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

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