Voor het installeren en updaten van VisualStudio Redist modules heb ik een script geschreven dit dit voor mij uitvoert bij een device

 

 

param ([switch]$Silent)

<#  

    .NOTES

    ===========================================================================

     Created on:    2023-12-12

     Created by:    Vincent van Unen

     Organization:  Xiphos SCALE IT

     Filename:      XIP-Install-VisualStudioRedistmodules.ps1

    ===========================================================================

    .DESCRIPTION

        Default Background for Teams Set

#>

#region Changelog

#################################################################################

# Version History

$ScriptAuthor = "Vincent van Unen"

$ScripVersion = "XXX"

$ScriptChangeDate = "XXXX-XX-XX"

$ScriptChangeLog = ""

$ScriptCurrentUser = $env:UserName

$Getcurrentdate = get-date -Format yyyy-MM-dd

$logname = "XIP-Install-VisualStudioRedistmodules"

<# Change Log

[0.1]     202X-XX-XX    -   First Setup of script

#>

#endregion Changelog

#Script functions

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12   # Set Security protocol naar TLS12

Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope LocalMachine -Force -WarningAction Ignore -ErrorAction Ignore

Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process -Force -WarningAction Ignore -ErrorAction Ignore

Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser -Force  -WarningAction Ignore -ErrorAction Ignore

# Checking & Creatiglog en temp directory

$XIPMyModuleDir1 = "C:\temp"                                                                                              # Check of c:\temp dir bestaat mocht deze niet bestaan dan word deze aangemaakt

    if(!(Test-Path -Path $XIPMyModuleDir1 )){ New-Item -ItemType directory -Path $XIPMyModuleDir1 }

$XIPMyModuleDir2 = "C:\tmp"                                                                                               # Check of c:\tmp dir bestaat mocht deze niet bestaan dan word deze aangemaakt      

    if(!(Test-Path -Path $XIPMyModuleDir2 )){ New-Item -ItemType directory -Path $XIPMyModuleDir2 }    

$XIPMyModuleDir3 = "C:\log"                                                                                               # Check of c:\log dir bestaat mocht deze niet bestaan dan word deze aangemaakt    

    if(!(Test-Path -Path $XIPMyModuleDir3 )){ New-Item -ItemType directory -Path $XIPMyModuleDir3 }    

cls    

Function WriteToLogFile{

    [CmdletBinding()]

    Param(

        [Parameter(Mandatory=$False)]

        [ValidateSet("INFO","WARN","ERROR","FATAL","DEBUG")]

        [String] $Level = "INFO",

        [Parameter(Mandatory=$True)]

        [string] $Message,

        [Parameter(Mandatory=$False)]

        [string] $logfile = "$XIPMyModuleDir3\$logname $Getcurrentdate.log"

    )

    if ($Message -eq " "){

        Add-Content $logfile -Value " " -ErrorAction SilentlyContinue

    }else{

        $Date = (Get-Date).ToUniversalTime().ToString('yyyy-MM-dd HH:mm:ss.fff')

        Add-Content $logfile -Value "[$date] [$Level] $Message" -ErrorAction SilentlyContinue

    }

}

WriteToLogFile -Message "Curent Date = $Getcurrentdate"

WriteToLogFile -Message "Script Autor = $ScriptAuthor"

WriteToLogFile -Message "Script Version = $ScripVersion"

WriteToLogFile -Message "Script ChangeDate = $ScriptChangeDate"

WriteToLogFile -Message "Current User Running this script = $ScriptCurrentUser"

$TranscriptFile = "$XIPMyModuleDir3\$Getcurrentdate $logname _transcript.log"

Start-Transcript -Path $TranscriptFile

$Repository = "PSGallery"

If (Get-PSRepository | Where-Object { $_.Name -eq $Repository -and $_.InstallationPolicy -ne "Trusted" }) {

    try {

        Write-Host "Trusting the repository: $Repository."

        Install-PackageProvider -Name "NuGet" -MinimumVersion 2.8.5.208 -Force

        Set-PSRepository -Name $Repository -InstallationPolicy "Trusted"

    }

    catch {

        Throw $_

    }

}

#region

#region Install the VcRedist module; https://vcredist.com/

$Module = "VcRedist"

Write-Host "Checking whether module is installed: $Module."

$installedModule = Get-Module -Name $Module -ListAvailable -ErrorAction "SilentlyContinue" | `

    Sort-Object -Property @{ Expression = { [System.Version]$_.Version }; Descending = $true } | `

    Select-Object -First 1

$publishedModule = Find-Module -Name $Module -ErrorAction "SilentlyContinue"

If (($Null -eq $installedModule) -or ([System.Version]$publishedModule.Version -gt [System.Version]$installedModule.Version)) {

    Write-Host "Installing module: $Module $($publishedModule.Version)."

    $params = @{

        Name               = $Module

        SkipPublisherCheck = $true

        Force              = $true

        ErrorAction        = "Stop"

    }

    Install-Module @params

}

#endregion

#region tasks/install apps

Try {

$Path = $XIPMyModuleDir1 + "\VcRedists"

Write-Host "Saving VcRedists to path: $Path."

New-Item -Path $Path -ItemType "Directory" -Force -ErrorAction "SilentlyContinue" > $null

Write-Host "Downloading and installing supported Microsoft Visual C++ Redistributables."

$Redists = Get-VcList | Save-VcRedist -Path $Path | Install-VcRedist -Silent

Write-Host "Installed Visual C++ Redistributables:"

$Redists | Select-Object -Property "Name", "Release", "Architecture", "Version" -Unique

Write-Host"Install complete."

}

catch {

        $errorMsg = $_.Exception.Message

        Write-Host "Error installing VCRedist $errorMsg"

    }

#endregion

Stop-Transcript