#Проверяем версию Firefox в интернете $uri = 'https://product-details.mozilla.org/1.0/firefox_versions.json' $FirefoxVersion = Invoke-WebRequest $uri -UseBasicParsing | ConvertFrom-Json | select -ExpandProperty LATEST_FIREFOX_vERSION $FirefoxDownloadX64 = "https://download-origin.cdn.mozilla.net/pub/firefox/releases/" + $FirefoxVersion + "/win64/ru/Firefox%20Setup%20" + $FirefoxVersion + ".msi" #Путь к папке с контентом $SCCMSource = '\\contoso.com\files\sccm\sccm-appsource\Applications\Browsers\Firefox' #Место куда кладём скачанный файл $OutFile = "C:\Temp\FirefoxSetup.msi" #Код сайта $SCCMSiteCode = 'S02' #Указываем коллекцию, на которую будет идти первый деплой $collection ="SU Point WKS MS Updates WAVE 1 (AD)" #Импортируем модуль SCCM IF (!(Get-Module ConfigurationManager)) {Import-Module (Join-Path $(Split-Path $env:SMS_ADMIN_UI_PATH) ConfigurationManager.psd1)} IF ($(pwd).path -ne "$SCCMSiteCode`:\") {Set-Location "$SCCMSiteCode`:"} #Функция логирования $logfile = "C:\temp\firefox.log" function WriteLog { Param ([string]$LogString) $Stamp = (Get-Date).toString("dd/MM/yyyy HH:mm:ss") $LogMessage = "$Stamp $LogString" Add-content $LogFile -value $LogMessage } #Задаём имя приложения $appnamemz = “Mozilla Firefox - autodeploy” #Получаем данные по текущей версии Mozilla со статусом Deployed = True $fversions = Get-CMApplication -Name $appnamemz -Fast | Select-Object SoftwareVersion, isdeployed | ?{$_.isdeployed -eq 'True'} | Select-Object -ExpandProperty SoftwareVersion Foreach ($fversion in $fversions) { if ($fversions -ge $FirefoxVersion) { Write-Output "Firefox in sccm is up to date!" WriteLog "Firefox in sccm is up to date!" } if ($fversions -lt $FirefoxVersion) { Write-Output "Firefox will be updated!" WriteLog "Firefox will be updated!" #Удаляем старый деплой Firefox Write-Output "Удаляем старый деплой Firefox" Get-CMApplicationDeployment -Name $appnamemz | Remove-CMApplicationDeployment -Force #Переименовываем и перемещаем старую версию Firefox Write-Output "Переименовываем и перемещаем старую версию Firefox" $app = Get-CMApplication -Name "$appnamemz" Set-CMApplication -InputObject $app -NewName "Firefox - $fversion" Move-CMObject -FolderPath "S02:\Application\Old version" -InputObject $app #Качаем новую версию Firefox Write-Output "Качаем новую версию Firefox" Invoke-WebRequest -Uri $FirefoxDownloadX64 -OutFile $OutFile # Перемещаем скачанный файл в сурс директорию Write-Output "Downloaded version: $FirefoxVersion" Writelog "Downloaded version: $FirefoxVersion" $Filename = $((get-item $OutFile).name) $destinationfolder = "$SCCMSource\$FirefoxVersion" Write-Output "Destination folder is $destinationfolder" Writelog "Destination folder is $destinationfolder" IF (!(test-path $destinationfolder)) { Writelog "$destinationfolder does not exist" [System.IO.Directory]::CreateDirectory($destinationfolder) Writelog "Creating $destinationfolder" [System.IO.File]::Move($OutFile,"$destinationfolder\$Filename") Writelog "Moving $OutFile to $destinationfolder" } #Создаём обновлённое приложение и перемещаем его в папку autodeploy Write-Output "Создаём обновлённое приложение" New-CMApplication -Name “$appnamemz” -Description “Mozilla Firefox” -AutoInstall $true $cla1=new-CMDetectionClauseFile -FileName "firefox.exe" -PropertyType Version -ExpectedValue $FirefoxVersion -ExpressionOperator GreaterEquals -Path "%ProgramFiles%\Mozilla Firefox" -Value -Is64Bit $logic1=$cla1.Setting.LogicalName Add-CMmsiDeploymentType -ApplicationName "$appnamemz" -ContentLocation "$destinationfolder\$filename" -DeploymentTypeName "Mozilla Firefox - $FirefoxVersion" -InstallationBehaviorType InstallForSystem -InstallCommand 'msiexec /i "FirefoxSetup.msi" /qn reboot=reallysuppress' -UserInteractionMode Hidden Set-CMmsiDeploymentType -ApplicationName "$appnamemz" -DeploymentTypeName "Mozilla Firefox - $FirefoxVersion" -AddDetectionClause $cla1 $app = Get-CMApplication -Name "$appnamemz" Move-CMObject -FolderPath "S02:\Application\Autodeploy" -InputObject $app #Добавление requirements $myGC = Get-CMGlobalCondition -Name "Disk space" $myRule = $myGC | New-CMRequirementRuleFreeDiskSpaceValue -PartitionOption System -RuleOperator GreaterEquals -Value1 1000 Set-CMMsiDeploymentType -ApplicationName "$appnamemz" -DeploymentTypeName "Mozilla Firefox - $FirefoxVersion" -AddRequirement $myRule #Удаляем детект типа MSI Write-Output "Удаляем детект типа MSI" $app = Get-CMDeploymentType -ApplicationName "$appnamemz" -DeploymentTypeName "Mozilla Firefox - $FirefoxVersion" $xml = $app.SDMPackageXML $old = (([regex]'(?<=SettingLogicalName=.)([^"]|\\")*').Matches($xml)).Value -match 'msi' $app | Set-CMMsiDeploymentType -RemoveDetectionClause $old #Дистрибьютим контент Write-Output "Дистрибьютим контент" Start-CMContentDistribution -ApplicationName "$appnamemz" -DistributionPointGroupName "All Distribution Points (Internal and IBCM)" Set-CMApplication -ApplicationName "$appnamemz" -SoftwareVersion $FirefoxVersion New-CMApplicationDeployment -Name "$appnamemz" -AvailableDateTime '01/01/2020 00:00:00' -CollectionName "$collection" -DeployAction Install -DeployPurpose Required -UserNotification HideAll } } Write-Output "Firefox Version in Web - $FirefoxVersion" Write-Output "Deployed Firefox Version in SCCM - $FirefoxVersion" Writelog "Firefox Version in Web - $FirefoxVersion" Writelog "Deployed Firefox Version in SCCM - $FirefoxVersion" Remove-Variable * -ErrorAction SilentlyContinue