I am trying to create a script that does the following things:
- Connect to File share that contains versions of Firefox. My organization keeps up to 4 Firefox versions in folders details their Version number (i.e “120.0.1”, “120.0”, “119.0.1”, “119.0”)
- Sort the files from greatest number to smallest number
- Select the greatest number
- Run the .msi program in the selected folder to the remote host.
For Further Clarification:
File Share = \Sparky\Endpoint\Mozilla Firefox*
.msi Folder = \Sparky\Endpoint\Mozilla Firefox\120.0.1\Firefox Setup 120.0.1
My Current Script:
#==============Universal Variable==============#
# $ToNatural is used to sort the selected folder
$ToNatural = { $_.Name -replace '\D', '0' }
$Computer = Read-Host "Please Enter Computer Name"
#==============Firefox==============#
# Selects whatever directory that has the greatest number
$newFirefox = Get-ChildItem "\\Sparky\Endpoint\\Mozilla Firefox" | Where-Object { $_.Name -match '\d' } | Sort-Object $ToNatural -Descending | Select-Object -First 1
# Check if a folder was found
if ($newFirefox) {
# Construct the absolute path to the Firefox folder
$firefoxFolderPath = "\\Sparky\Endpoint\\Mozilla Firefox\$($newFirefox.Name)"
}
# New variable that represents content of the selected folder
$Firefox = Get-ChildItem $firefoxFolderPath
# Run the firefox.msi file
if ($Firefox -and $Firefox.Count -gt 0) {
Invoke-Command -ComputerName $Computer -ScriptBlock {Start-Process msiexec -ArgumentList "/i", "$Firefox", "/qn" -NoNewWindow}
}
I edited some details for this post, so there may be slight errors. But essentially whenever I run this code on a remote computer, Firefox does not install. My assumption is that it because it is not running the .msi from the selected folder.