Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过Vagrant在Vagrant box中运行PowerShell脚本_Powershell_Vagrant - Fatal编程技术网

通过Vagrant在Vagrant box中运行PowerShell脚本

通过Vagrant在Vagrant box中运行PowerShell脚本,powershell,vagrant,Powershell,Vagrant,我试图执行这些命令在Vagrant box中安装.exe文件 # Copyfile from network shared folder to folder in host machine Get-ChildItem "L:\" -Filter *.exe | Where Name -NotMatch '.*NoDB\.exe$' | % { New-Object psobject -Property @{ No = [int]([regex]::Match($_.Name, '(?&

我试图执行这些命令在Vagrant box中安装.exe文件

# Copyfile from network shared folder to folder in host machine

Get-ChildItem "L:\" -Filter *.exe | Where Name -NotMatch '.*NoDB\.exe$' | % {
New-Object psobject -Property @{
    No = [int]([regex]::Match($_.Name, '(?<=CL)\d+').Value)
    Name = $_.FullName
}

} | Sort No -Descending | Select -ExpandProperty Name -First 1 | Copy-Item -Destination "C:\VagrantBoxes\Win8"

# Copy installation script to Vagrant folder which is share with Vagrant

Copy-Item -Path "C:\Users\PS\Des\Scr_Re_Win_8\Install_Ort.ps1" -Destination "C:\VagrantBoxes\Win8"

# Navigate to Vagrant machine folder

CD "C:\VagrantBoxes\Win8"

# Check if Vagrant is up

 vagrant.exe up

# Run PowerShell in Vagrant

vagrant.exe powershell

# Navigate to the folder which is shared with Vagrant

CD "C:\vagrant"

#Set policy to Unrestricted

Set-ExecutionPolicy Unrestricted -Force

# Install Chocolatey

iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))

# Install .net 3.5

   choco install dotnet3.5 -force

 # Run Ort installation script

 .\Install_Ort.ps1

我看到PowerShell控制台在Vagrant中处于活动状态,但命令不会通过Vagrant框中的PowerShell执行。我可以手动键入命令,但不能作为脚本的一部分。

您不能从当前运行的同一个powershell脚本执行命令,它将安装在主机上

您想要的是将该命令传递给VM的来宾powershell,您可以使用
-c命令
这样的选项

vagrant.exe powershell -c "CD C:\vagrant"
vagrant.exe powershell -c "Set-ExecutionPolicy Unrestricted -Force"
...

嘿,Mikhail,您可能需要将
vagrant.exe powershell
下面的任何内容放入一个新脚本中,并在vagrant中调用该脚本。“但我不熟悉麻省理工学院的流浪汉。”马丁布兰德尔,事实上,这可能是最好的解决方案,我们有:)但米哈伊尔想用PS来做所有的事情;使用回答中建议的
命令
选项是另一种选择,并确保脚本将在guest@Fr好吧,那么你为他提供了正确的解决方案,也解释了问题。马丁,谢谢你的建议。是的,@FrédéricHenri是对的。谢谢你们两位,太好了!它起作用了。几乎。。。在最后一步“运行Ort安装脚本vagrant.exe powershell-c”\Install\u Ort.ps1“失败。以下WinRM命令以非零退出状态响应。您是否可以尝试使用
invokeeexpression
调用PS并使用完整路径。。在第一次调用中完成
cd
后,不确定它是否会保留位置,如果它像ssh一样,则它会在每次frédéric Henri运行时启动新连接!我使用了这个cmdlet“vagrant.exe powershell-c”c:\vagrant\Install_Ortho.ps1 | Invoke Expression”,它成功了!万岁!
vagrant.exe powershell -c "CD C:\vagrant"
vagrant.exe powershell -c "Set-ExecutionPolicy Unrestricted -Force"
...