无法在Vagrant安装的Windows 2008 R2 Standard中运行PowerShell脚本

时间:2016-07-19 15:38:34

标签: windows powershell vagrant

我无法运行此PowerShell脚本

# Execute .exe file

 Get-ChildItem "C:\vagrant" -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=server -UpdateMaterials=yestoall -UpgradeDBIfRequired=yes"}
Windows Windows 2008 R2 Standard中的

因为

**********************
 Windows PowerShell Transcript Start
 Start time: 20160719080730
 Username  : VAGRANT-2008R2\vagrant 
 Machine      : VAGRANT-2008R2 (Microsoft Windows NT 6.1.7601 Service Pack 1) 
 **********************
 Transcript started, output file is C:\Users\vagrant\Documents\PowerShell_transc
ript.20160719080730.txt
Where-Object : Cannot bind parameter 'FilterScript'. Cannot convert the "Name" 
value of type "System.String" to type "System.Management.Automation.ScriptBlock
".
At C:\vagrant\Install_Ortho.ps1:7 char:49
+ Get-ChildItem "C:\vagrant" -Filter *.exe | Where <<<<  Name -NotMatch '.*NoDB
\.exe$' | % {
+ CategoryInfo          : InvalidArgument: (:) [Where-Object], ParameterBi 
ndingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerSh 
  ell.Commands.WhereObjectCommand

 **********************
 Windows PowerShell Transcript End
 End time: 20160719080730
 **********************

我尝试使用这个建议“尝试使用{}而不是括号围绕你的论点。”同样的错误。

1 个答案:

答案 0 :(得分:2)

此语法:

Where Property -[OperatorAsParameterName] 'value'
PowerShell 3.0中引入了

- Windows 2008 R2附带了PowerShell 2.0!

版本2.0等效于:

Where {$_.Name -NotMatch '.*NoDB\.exe$'}

您可以修复一个实例,但是脚本的其他部分可能会失败,并且您必须继续修复3.0版语法,直到您重写了整个事件

我建议找一个2008R2特定版本的Vagrant,或者将此发现作为与开发团队的兼容性错误提交