Reputation: 411
I try execute .exe file which was copied from network folder to host folder with keys for silent installation by using this script:
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 | Invoke-Item -s2 -sp"-SilentInstallation=standalone -UpdateMaterials=yestoall -UpgradeDBIfRequired=yes"
But I receive error:
Invoke-Item : A parameter cannot be found that matches parameter name 's2'.
At line:20 char:78
+ ... ding | Select -ExpandProperty Name -First 1 | Invoke-Item -s2 -sp"-Si ...
+ ~~~
+ CategoryInfo : InvalidArgument: (:) [Invoke-Item], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.InvokeItemCommand
Upvotes: 1
Views: 68
Reputation: 58921
You get the error because you pass the parameters to the Invoke-Item
cmdlet and not to your application,
Try to invoke your executeable with &
and pass the parameters:
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"}
Upvotes: 1