2016-09-06 88 views
1

创建流浪文件我的这些线,我想补充到流浪的文件,我想通过PowerShell的通过PowerShell的

Vagrant.configure("2") do |config| 
config.vm.communicator = "winrm" 
config.vm.box = "Win_10_V.box" 
config.vm.provider "virtualbox" do |vb| 
    vb.customize ["modifyvm", :id, "--usb", "on"] 
    vb.customize ["modifyvm", :id, "--usbehci", "on"]  
    vb.customize ['usbfilter', 'add', '0', '--target', :id, '--name', 'SmartCard', '--vendorid', '0x096E', '--productid', '0x0007'] 
    vb.gui = true 
end 
end 

创建这个我试过PowerShell命令,但它不会因为多次的合作“符号。

New-Item "D:\VV\Vagrantfile" -type file -force -value "Vagrant.configure("2") do |config| 
config.vm.communicator = "winrm" 
config.vm.box = "W_1.box" 
config.vm.provider "virtualbox" do |vb| 
    vb.customize ["modifyvm", :id, "--usb", "on"] 
    vb.customize ["modifyvm", :id, "--usbehci", "on"]  
    vb.customize ['usbfilter', 'add', '0', '--target', :id, '--name', 'SmartCard', '--vendorid', '0x096E', '--productid', '0x0007'] 
    vb.gui = true 
end 
end" 

这是错误输出

New-Item : A positional parameter cannot be found that accepts argument '2) do |config| 
config.vm.communicator = winrm 
config.vm.box = Win_10_V.box 
config.vm.provider virtualbox do |vb| 
    vb.customize [modifyvm, :id, --usb, on] 
    vb.customize [modifyvm, :id, --usbehci, on]   
    vb.customize ['usbfilter', 'add', '0', '--target', :id, '--name', 'SmartCard', '--vendorid', '0x096E', '--productid', '0x0007'] 
    vb.gui = true 
end 
end'. 
At line:1 char:1 
+ New-Item "D:\VV\Vagrantfile" -type file -force -value "Vagrant.configu ... 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
+ CategoryInfo   : InvalidArgument: (:) [New-Item], ParameterBindingException 
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.NewItemCommand 

我知道我有POSI但我需要它们在我的Vagranfile中

回答

2

问题是,您传递的值(在2之前)的双引号会终止您作为值传递的字符串。重新写使用here-string

$value = @" 
"Vagrant.configure("2") do |config| 
config.vm.communicator = "winrm" 
config.vm.box = "W_1.box" 
config.vm.provider "virtualbox" do |vb| 
    vb.customize ["modifyvm", :id, "--usb", "on"] 
    vb.customize ["modifyvm", :id, "--usbehci", "on"]  
    vb.customize ['usbfilter', 'add', '0', '--target', :id, '--name', 'SmartCard', '--vendorid', '0x096E', '--productid', '0x0007'] 
    vb.gui = true 
end 
end 
"@ 

New-Item "D:\VV\Vagrantfile" -type file -force -value $value 

这将让你有在字符串中嵌入引号。

+1

非常感谢!现在一切都按预期工作。 –