Run PowerShell script (installation of .exe file i

2019-09-10 11:05发布

问题:

I have script which installs software (.exe file) via PowerShell

Get-ChildItem "D:\" -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 | 
Foreach { & $_ -s2 -sp"-SilentInstallation=standalone-  UpdateMaterials=yestoall -UpgradeDBIfRequired=yes"}

I need to run this script via PowerShell so I created a script for this

# copy installation script to Vagrant folder

Copy-Item -Path "C:\Users\Username\Desktop\Scripts\Installation_Ortho.ps1" -Destination "C:\VagrantBoxes\Win8"

 # Navigate to vagrant folder

 CD "C:\VagrantBoxes\Win8"

  #vagrant powershell

 vagrant.exe powershell

 # navigate to the folder which is shared with Vagrant

 CD "C:\vagrant"

Unfortunately I receive an error

 C:\VagrantBoxes\Win8> vagrant powershell
==> default: Detecting if a remote PowerShell connection can be made with the guest...
default: Creating powershell session to 127.0.0.1:55985
default: Username: vagrant

Oops, something went wrong.  Please report this bug with the details  below.
Report on GitHub: https://github.com/lzybkr/PSReadLine/issues/new

Last 0 Keys:


Exception:
System.IO.IOException: The handle is invalid.

at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.Console.GetBufferInfo(Boolean throwOnNoConsole, Boolean& succeeded)
at Microsoft.PowerShell.PSConsoleReadLine.Initialize(Runspace runspace, EngineIntrinsics engineIntrinsics)
at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics)

I am looking for solution which helps me:

1) Navigate through PowerShell to a folder inside Vagrant box where script is placed;

2) Execute a PowerShell script inside Vagrant box and receive installed software in Vagrant boxe.