Loading

Download and install the latest version of 5 base applications

An acquaintance saw my MECM lab environment the other day and saw how I was automatically downloading the latest versions of some applications (which were then automatically distributed and installed on the client computers), and thought it looked “cool”.
My acquaintance does not run MECM, or similar systems. But wanted me to show how he could automatically download and install latest version of some base applications.
So, I took my scripts and tweaked them for my acquaintance. Which then I thought I’d post them here (because it’s been ages since I posted anything).

Here you go, 5 applications that download and install automatically.

7-Zip

# 7-Zip
$7ZipDir = "C:\tmp\Latest\Apps\"
$dlurl = 'https://7-zip.org/' + (Invoke-WebRequest -Uri 'https://7-zip.org/download.html' | Select-Object -ExpandProperty Links | Where-Object {($_.innerHTML -eq 'Download') -and ($_.href -like "a/*") -and ($_.href -like "*x64.msi")} | Select-Object -First 1 | Select-Object -ExpandProperty href)
# above code borrowed from: https://perplexity.nl/windows-powershell/installing-or-updating-7-zip-using-powershell/
$installerPath = Join-Path $7ZipDir (Split-Path $dlurl -Leaf)
Invoke-WebRequest $dlurl -OutFile $7ZipDir\7z-x64.msi
Start-Process -FilePath "msiexec.exe" -ArgumentList "/i `"$7ZipDir\7z-x64.msi`" /qn ALLUSERS=2 REBOOT=REALLYSUPPRESS" -Wait -PassThru

# Google Chrome

# Google Chrome
$ChromeDir = "C:\tmp\Latest\Apps\GoogleChromeStandaloneEnterprise64.msi"
Invoke-WebRequest -Uri "http://dl.google.com/edgedl/chrome/install/GoogleChromeStandaloneEnterprise64.msi" -OutFile $ChromeDir
Start-Process msiexec.exe -Wait -ArgumentList '/I $ChromeDir /qn ALLUSERS=2 REBOOT=REALLYSUPPRESS'
Start-Process -FilePath "msiexec.exe" -ArgumentList "/i `"C:\tmp\Latest\Apps\GoogleChromeStandaloneEnterprise64.msi`" /qn ALLUSERS=2 REBOOT=REALLYSUPPRESS" -Wait -PassThru

Microsoft PowerShell 7

# Microsoft PowerShell 7
$metadata = Invoke-RestMethod https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/metadata.json
$release = $metadata.ReleaseTag -replace '^v';"https://github.com/PowerShell/PowerShell/releases/download/v${release}/PowerShell-${release}-win-x64.msi"
#above code borrowed from: Ruckzuck.tools
$PowerShellDir = "C:\tmp\Latest\Apps\PowerShell-7-win-x64.msi"
Invoke-WebRequest -Uri "https://github.com/PowerShell/PowerShell/releases/download/v${release}/PowerShell-${release}-win-x64.msi" -OutFile $PowerShellDir
Start-Process -FilePath "msiexec.exe" -ArgumentList "/i `"C:\tmp\Latest\Apps\PowerShell-7-win-x64.msi`" /qn ALLUSERS=2 REBOOT=REALLYSUPPRESS" -Wait -PassThru

Mozilla Firefox

# Mozilla Firefox
$FirefoxDir = "C:\tmp\Latest\Apps\FirefoxSetup.msi"
Invoke-WebRequest -Uri "https://download.mozilla.org/?product=firefox-msi-latest-ssl&os=win64&lang=en-US" -OutFile $FirefoxDir
Start-Process -FilePath "msiexec.exe" -ArgumentList "/i `"C:\tmp\Latest\Apps\FirefoxSetup.msi`" /qn" -Wait -PassThru

Notepad++

# Notepad++
$NotepadDir = 'C:\tmp\Latest\Apps\'
$href = ((Invoke-WebRequest -Uri 'https://notepad-plus-plus.org/downloads/').Links | Where-Object { $_.innerText -match 'current version' }).href
$downloadUrl = ((Invoke-WebRequest "https://notepad-plus-plus.org/$href").Links | Where-Object { $_.innerHTML -match 'installer' -and $_.href -match 'x64.exe' }).href
Invoke-RestMethod $downloadUrl -OutFile "$NotepadDir\npp.installer.x64.exe"
Start-Process -FilePath "$NotepadDir\npp.installer.x64.exe" -ArgumentList "/S" -PassThru

 

Psst, are you using Microsoft 365? Don’t miss out my old blog post, Microsoft 365 Apps (Office 365) hantering i MECM (SCCM)

 

#7-Zip, #GoogleChrome, #MicrosoftPowerShell7, #MozillaFirefox, #Notepad++, #Microsoft365Apps

Uppdatera Configmgr Content, där det behövs

Återigen, Rikard Rönnkvist spar mig massor av tid med sina PowerShell-script, tack!

PARAM (
    $sccmServer = "configmgr.snowland.se",
    $sccmSiteCode = "ABC",
    $failStates = "2, 3, 5, 6", # Retrying and Failed (Both Install and Removal)
    $packageTypes = "0, 3, 4, 8, 257, 258" # Not checking 5 (SUP) due to automatic deployments
)
 
Write-Host "Searching for failed content distributions"
ForEach ($FailedDist in (Get-WmiObject -ComputerName $sccmServer -Namespace "ROOT\SMS\Site_$($sccmSiteCode)" -Query "SELECT * FROM SMS_PackageStatusDistPointsSummarizer WHERE State IN ($($failStates)) AND PackageType IN ($($packageTypes))" | Sort-Object PackageID)) {
     
    # Figure out servername from NalPath
    $failedServer = $FailedDist.ServerNALPath.Substring($FailedDist.ServerNALPath.LastIndexOf("]")+3).Trim("\")
 
    # Get the distribution points that content wouldn't distribute to
    ForEach ($FailedDPDist in (Get-WmiObject -ComputerName $sccmServer -Namespace "ROOT\SMS\Site_$($sccmSiteCode)" -Query "SELECT * FROM SMS_DistributionPoint WHERE SiteCode='$($FailedDist.SiteCode)' AND PackageID='$($FailedDist.PackageID)' AND ServerNALPath LIKE '%$($failedServer)%'") ) {
        # Refresh content on the selected DP
        Write-Host "Refreshing $($FailedDPDist.PackageID), type $($FailedDist.PackageType) in state $($FailedDist.State) on $($failedServer)"
        $FailedDPDist.RefreshNow = $true
        $FailedDPDist.Put() | Out-Null
    }
}
 
Write-Host "Done!"

Tack till Rikard Rönnkvist, källa: SnowLand

Exportera / Importera Boot-image drivrutiner till ny Boot-image

Återigen, ett mycket bra PowerShell-script som besparar massa tid.

Function Export-BootImageDrivers {
    PARAM (
        [String] $ImageId,
        [String] $ExportXml
    )
  
    $drivers = @{}
    (Get-CMBootImage -Id $ImageId).ReferencedDrivers | ForEach-Object {
        Write-Verbose "Found driver ID - $($_.Id)"
 
        $drivers.Add($_.Id, $_.SourcePath)
    }
 
    $drivers | Export-Clixml -Path $ExportXml
}
 
Function Import-BootImageDrivers {
    PARAM (
        [String] $ImageId,
        [String] $ExportXml
    )
 
    $BootImage = Get-CMBootImage -Id $ImageId
    $drivers = Import-Clixml -Path $ExportXml
    $drivers.GetEnumerator() | ForEach-Object {
        Write-Verbose "Adding driver ID - $($_.Name)"
        Set-CMDriver -Id $_.Name -AddBootImagePackage $BootImage -UpdateDistributionPointsforBootImagePackage $false -Force
    }
}

Exportera först drivrutinerna

Export-BootImageDrivers -ImageId “ABC00123” -ExportXml “D:\Script\PS\drivers.xml”

Uppgradera Boot-imagen

Sedan importera drivrutinerna

Import-BootImageDrivers -ImageId “ABC00345” -ExportXml “D:\Script\PS\drivers.xml”

Tack till Rikard Rönnkvist, källa: SnowLand