簡體   English   中英

通過Vagrant框內的Vagrant運行PowerShell腳本

[英]Run PowerShell script via Vagrant inside Vagrant box

我試圖執行這些命令以在Vagrant框中安裝.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

但是最后,當在“ Vagrant”框中激活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 COMMAND選項執行此操作,例如

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM