I try to copy newest file from network folder and execute it. In location where I need to copy 2017 file I have 2015 file, but I need to execute only 2017 file.
# Copyfile from network shared folder to folder in host machine
Get-ChildItem "\\r\Pro\Al\Ort\Daily B\2017\x64" -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:\Users\User Name\Desktop"
# Execute .exe file
Get-ChildItem "C:\Users\User Name\Desktop" -Include *exe*, *2017* | 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"}
When I execute this script nothing happens.