About
PowerShell scripts

PowerShell - Windows Update Scripts

Categories

Files

Display a Script Requirement Pass/Fail

FileName: Write-RequirementResults.ps1

Categories: Reboot, Admin, Windows 11

Description
  • This is a visual indicator with error messages if the script cannot execute
  • Verify Windows 11 (WinGet can run on late versions of Windows 10 but it is no longer supported)
  • Verify the script is executing as an admin
  • Verify that a reboot is not needed

Code:

. .\Test-Windows11
. .\Test-Administrator
. .\Test-RebootPending

function Write-RequirementResults {
	Write-Host "Requirement Results:"
	Write-Host "--------------------"
	if (Test-RebootPending) {
		Write-Host "Pending Reboot: FAIL" -ForegroundColor Red
		Exit-IfRebootPending
	} else {
		Write-Host "Pending Reboot: PASS" -ForegroundColor Green
	}
	IF (Test-Administrator) {
		Write-Host "Administrator: PASS" -ForegroundColor Green
	} else {
		Write-Host "Administrator: FAIL" -ForegroundColor Red
		Exit-IfRebootPending
	}
	IF (Test-Windows11) {
		Write-Host "Windows 11: PASS" -ForegroundColor Green
	} else {
		Write-Host "Windows 11: FAIL" -ForegroundColor Red
		Exit-IfRebootPending
	}
	Write-Host "--------------------"
}

Exit If Reboot Pending

FileName: Exit-IfRebootPending.ps1

Categories: Reboot

Description
  • Prompt user if reboot is pending.
  • Exit or Reboot based on user input.

Code:

. .\Test-RebootPending

# Function to exit is script if pending reboot


function Exit-IfRebootPending {
  if (Test-RebootPending) {
    Write-Host "A system reboot is pending. Please reboot your computer and run this script again."
      if ($PSCmdlet.ShouldContinue("A reboot is required. Do you want to reboot now?", "Reboot Confirmation")) {
          & ".\\Reboot.ps1"
      }
    exit
  }
  Write-Verbose "No pending reboot detected. Proceeding with updates..."
}

Exit Script If Not Running As Administrator

FileName: Exit-IfNotAdmin.ps1

Categories: Admin

Description
  • Exit the script if it is not running with administrator privileges. This is useful to prevent the script from executing actions that require elevated permissions, which could lead to errors or unintended consequences if run without the necessary rights.

Code:

. .\Test-Administrator  
function Exit-IfNotAdmin {
  if (-not (Test-Administrator)) {
    exit
  }
}

Install App Installer If Not Installed

FileName: Install-AppInstaller.ps1

Categories: Admin, Application Check, WinGet

Description
  • Not all versions of Windows 10 or Windows 11 come with the Microsoft Store version of App Installer, which is required for WinGet. This script checks if App Installer is installed and attempts to install it if it is not present. It also checks for pending reboots before attempting installation.

Code:

. .\Test-Winget
. .\Test-Administrator
. .\Exit-IfRebootPending

function Install-AppInstaller {
  if (-not (Test-Administrator)) {
        Write-Host "User is not an administrator. Installation will be skipped." -ForegroundColor Yellow
        EXIT
    }
    
    # Check if winget is available
  if (-not (Test-Winget )) {
      Write-Verbose "winget is not found. Installing the latest App Installer..."

      try {
          # Set progress preference to silently continue
          $progressPreference = 'SilentlyContinue'

          # Get the latest Winget release URL
          $latestWingetMsixBundleUri = (Invoke-RestMethod https://api.github.com/repos/microsoft/winget-cli/releases/latest).assets.browser_download_url | Where-Object { $_.EndsWith(".msixbundle") }

          $latestWingetMsixBundle = $latestWingetMsixBundleUri.Split("/")[-1]

          # Download Winget installer
          Invoke-WebRequest -Uri $latestWingetMsixBundleUri -OutFile "./$latestWingetMsixBundle"

          # Download VCLibs dependency
          Invoke-WebRequest -Uri https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx -OutFile Microsoft.VCLibs.x64.14.00.Desktop.appx

          # Install VCLibs
          Add-AppxPackage Microsoft.VCLibs.x64.14.00.Desktop.appx

          # Install Winget
          Add-AppxPackage $latestWingetMsixBundle

          Write-Host "App Installer (winget) has been installed successfully." -ForegroundColor Blue

          # Clean up downloaded files
          Remove-Item "./$latestWingetMsixBundle"
          Remove-Item Microsoft.VCLibs.x64.14.00.Desktop.appx

      } catch {
          Write-Host "Failed to install App Installer. Error: $($_)" -ForegroundColor Red
      }
  }
    Exit-IfRebootPending
}

Install WinGet If Not Installed

FileName: Install-WingetAppIfNotInstalled.ps1

Categories: WinGet, Admin, Reboot

Description
  • Verify if WinGet is installed on the system and install it if not.

Code:

. .\Test-Administrator
. .\Test-ApplicationInstalled
. .\Test-Winget
. .\Exit-IfRebootPending

function Install-WingetAppIfNotInstalled {
  param (
    [string]$appId
  )
  Exit-IfRebootPending
  if (-not(Test-Administrator)) {
    Write-Host "User is not an administrator. Installation will be skipped." -ForegroundColor Yellow
    return
  }

  if (-not(Test-Winget)) {
    Write-Host "Winget is not installed. Installing Winget..."
    Install-Winget
  }

  if (-not (Test-ApplicationInstalled -appId $appId)) {
    Write-Host "Installing $appId..."
    winget install --id $appId --exact --accept-package-agreements --accept-source-agreements
  }

  Exit-IfRebootPending
}

Is Microsoft Edge Installed

FileName: Test-MicrosoftEdge.ps1

Categories: Application Check, Edge

Description
  • Verify if the Microsoft Edge Browser is installed

Code:

function Test-MicrosoftEdge {
	$updaterPath = "${env:ProgramFiles(x86)}\Microsoft\EdgeUpdate\MicrosoftEdgeUpdate.exe"
	
	if (Test-Path $updaterPath) {
		return $true
	} else {
		#Write-Verbose "Microsoft Edge is not installed."
		return $false}
}

Is Windows Defender Anti-Virus Active

FileName: Test-DefenderActive.ps1

Categories: Application Check, Windows Defender

Description
  • Is Windows Defender Running and Active

Code:

function Test-DefenderActive {
  $defenderStatus = Get-MpComputerStatus
  if ($defenderStatus.AntispywareEnabled -eq $true -or $defenderStatus.AntivirusEnabled -eq $true) {
  	return $true
  } else {
  	return $false
}

Notifies User if specific programs are installed

FileName: Write-InstallCheck.ps1

Categories: Application Check

Description
  • Status check of the installation status of specific applications

Code:

. .\Test-DefenderActive
. .\Test-Winget
. .\Test-MicrosoftEdge
. .\Test-Nvidia
. .\Test-ApplicationInstalled

function Write-InstallCheck {
	Write-Host "Install Check:"
	Write-Host "--------------------"
	IF (Test-DefenderActive) {
		Write-Host "Windows Defender Active: PASS" -ForegroundColor Green
	} else {
		Write-Host "Windows Defender: Update will be skipped" 
	}
	if (Test-Winget) {
		Write-Host "Winget: PRESENT" -ForegroundColor Green
	} else {
		Write-Host "Winget: install to be attempted" -ForegroundColor Blue
	}
	if (Test-MicrosoftEdge) {
		Write-Host "Microsoft Edge: PRESENT" -ForegroundColor Green
	} else {
		Write-Host "Microsoft Edge: install to be attempted" -ForegroundColor Blue
	}
	if (Test-Nvidia) {
		$VideoController = Get-WmiObject -ClassName Win32_VideoController | Where-Object { $_.Name -match "NVIDIA" }
    	$ins_version = ($VideoController.DriverVersion.Replace('.', '')[-5..-1] -join '').insert(3, '.')
		Write-Host "Nvidia: Present - `t$ins_version" -ForegroundColor Green
	} else {
		Write-Host "Nvidia: Card Not Present" -ForegroundColor Blue
	}

	if (Test-Winget) {
		if (Test-ApplicationInstalled -appId "Microsoft.PowerShell") {
			Write-Host "PowerShell: PRESENT" -ForegroundColor Green
		} else {
			Write-Host "PowerShell: install to be attempted" -ForegroundColor Blue
		}
		if (Test-ApplicationInstalled -appId "Microsoft.WindowsTerminal") {
			Write-Host "Windows Terminal: PRESENT" -ForegroundColor Green
		} else {
		Write-Host "Windows Terminal: install to be attempted" -ForegroundColor Blue
		}
		if (Test-ApplicationInstalled -appId "Git.Git") {
			Write-Host "Git: PRESENT" -ForegroundColor Green
		} else {
			Write-Host "Git: install to be attempted" -ForegroundColor Blue
		}
		if (Test-ApplicationInstalled -appId "7zip.7zip") {
			Write-Host "7-Zip: PRESENT" -ForegroundColor Green
		} else {
			Write-Host "7-Zip: install to be attempted" -ForegroundColor Blue
		}
		if (Test-ApplicationInstalled -appId "Microsoft.VisualStudioCode") {
			Write-Host "Visual Studio Code: PRESENT" -ForegroundColor Green
		} else {
			Write-Host "Visual Studio Code: install to be attempted" -ForegroundColor Blue
		}
		if (Test-ApplicationInstalled -appId "XP89DCGQ3K6VLD") {
			Write-Host "Windows PowerToys: PRESENT" -ForegroundColor Green
		} else {
			Write-Host "Windows PowerToys: install to be attempted" -ForegroundColor Blue
		}
	}
		Write-Host "--------------------"
}

Nvidia Driver Check

FileName: Test-Nvidia.ps1

Categories: Application Check, Nvidia Drivers

Description
  • I prefer this method to force a check and update of Nvidia drivers so I can check everythign at once and prevent the install prompt after I have all my development applications open.

Code:

function Test-Nvidia {
	
	try {
		#Check for NVIDIA drivers
		$VideoController = Get-WmiObject -ClassName Win32_VideoController | Where-Object { $_.Name -match "NVIDIA" }
		$ins_version = ($VideoController.DriverVersion.Replace('.', '')[-5..-1] -join '').insert(3, '.')
		return $true
	}
	catch {
    	#Write-Host -ForegroundColor Yellow "Unable to detect a compatible Nvidia device."
	    return $false
	}
}

Putting It All Together

FileName: UpdateComputer.ps1

Categories: Admin, WinGet, Application Check, Admin, Reboot

Description
  • A PowerShell script that combines all the previous functions to check for pending reboots, verify administrator privileges, check for WinGet and specific applications, and then proceed to install or update applications as needed. It also includes updates for Microsoft Edge, Windows updates, and Windows Defender.

Code:

[CmdletBinding()]

param(
    $VerbosePreference,
  [string]$InstallSet = "None"
)


Clear-Host


# Importing necessary modules

. .\Test-Windows11
. .\Test-RebootPending
. .\Test-Administrator
. .\Update-MicrosoftEdge
. .\Update-Defender
. .\Write-RequirementResults
. .\Write-InstallCheck
. .\Update-Windows
. .\Install-AppInstaller
. .\Update-VsCodeExtensions
. .\Exit-IfRebootPending
. .\Exit-IfNotAdmin
. .\Exit-IfNotWindows11
. .\Install-WingetAppIfNotInstalled


#Write-RequirementResults 

Write-RequirementResults


#Exit if Requirements not met

Exit-IfRebootPending
Exit-IfNotWindows11
Exit-IfNotAdmin

Install-AppInstaller

$SharedAppId = @(

#This is the default apps that are installed in every set other than the default "none"  
  "Microsoft.PowerShell"
  "Microsoft.WindowsTerminal"
  "XP89DCGQ3K6VLD" # PowerToys from Windows Store
  "Grammarly.Grammarly"
  "Grammarly.Grammarly.Office"
)


#Developer Install Set

if ($InstallSet -eq "developer") {
  
  $appId = $SharedAppId + @(
    "Microsoft.DotNet.SDK.8"
    "Microsoft.DotNet.SDK.9"
    "Microsoft.DotNet.DesktopRuntime.8"
    "Microsoft.DotNet.DesktopRuntime.9"
    "Microsoft.DotNet.AspNetCore.8"
    "Microsoft.DotNet.AspNetCore.9"
    "Microsoft.SQLServerManagementStudio"
    "Microsoft.WSL"
    "Canonical.Ubuntu"
    "Microsoft.VisualStudioCode"
    "Microsoft.VisualStudio.2022.Community"
    "Git.Git"
    "GitHub.GitHubDesktop"
    "7zip.7zip"
    "CodeSector.TeraCopy"
    "CodeSector.DirectFolders"
    "Brave.Brave"
    "Microsoft.SQLServer.2022.Developer"
    "Amazon.AWSCLI"
  )
  # use the next line in a loop
  foreach ($id in $appId) {
    Install-WingetAppIfNotInstalled -appId $id
  }

  $vsCodeExtensions = @(
    "github.copilot"
    "github.copilot-chat"
    "ms-dotnettools.csdevkit"
    "ms-dotnettools.csharp"
    "ms-vscode.powershell"
  )

  foreach ($extension in $vsCodeExtensions) {
    code --install-extension $extension --force
  }

}

# Standard Install Set

if ($InstallSet -eq "standard") {
  $appId = $SharedAppId + @(
    "7zip.7zip"
    #"Chocolatey.ChocolateyGUI"
  )
  # use the next line in a loop
  foreach ($id in $appId) {
    Install-WingetAppIfNotInstalled -appId $id
  }
}


#Write-InstallCheck


# Update Microsoft Edge

# It will appear in WinGet, but cannot update without opening Edge and checking for updates in settings --> about.

Update-MicrosoftEdge


Write-Host "WinGet updating all applications" -ForegroundColor Blue

#winget source reset --force

winget upgrade --all --accept-package-agreements --accept-source-agreements --include-unknown


# Update VS Code Extensions, if VS Code is installed 

Update-VsCodeExtensions


cd "C:\Program Files (x86)\Microsoft Visual Studio\Installer"

.\setup.exe updateall  --quiet --force | Out-Null

cd \scripts


#Install Windows update

Update-Windows


# Update Windows Defender if the AntiSpyware or Antivirus is enabled

Update-Defender

# Update DotNet New templates
dotnet new update

Reboot Windows

FileName: Reboot.ps1

Categories: Reboot

Description
  • A PowerShell script to reboot Windows immediately.
  • /g Fully shuts down and restarts the computer.
  • /t <xxx> Sets the time-out period before shutdown to xxx seconds. The valid range is 0-315360000 (10 years), with a default of 30.
  • /d p:4:1 Provides the reason for the shutdown. In this case, it indicates Application Maintenance with a planned shutdown.

Code:

shutdown /g /t 0 /d p:4:1

Test If Application Is Installed

FileName: Test-ApplicationInstalled.ps1

Categories: WinGet, Application Check

Description
  • Uses WinGet to check if an application is installed based on its application ID. This function can be used to verify the presence of specific software before attempting installation or performing other actions.

Code:

. .\Test-Winget

# create a function to use winget list to determine if an application is installed

# use the ID as a parameter

function Test-ApplicationInstalled {
  param (
    [string]$appId
  )
  if (Test-Winget) {

    try {
      $wingetList = winget list --id $appId --exact | Select-String $appId
      if ($wingetList) {
        return $true
      }
    }
    catch {
      return $false
    }
    
  }
  return $false
}

Test PowerShell Script For Local Admin Privileges

FileName: Test-Administrator.ps1

Categories: Admin

Description
  • PowerShell to verify if the script is executed as an administrator. It will return FALSE if the current user is a local administrator but the console is not executed as a local administrator.
  • It could easily be modified to verify other user names passed into the function.

Code:

# Check if running as administrator

function Test-Administrator {
  $currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
  $principal = New-Object Security.Principal.WindowsPrincipal($currentUser)
  $isAdmin = $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)

  if ($isAdmin) { 
    Write-Verbose "Administrator Check: PASS"
    return $true
  } 
  Write-Verbose "This script requires Administrator privileges"
  return $false
}

Test Reboot Pending

FileName: Test-RebootPending.ps1

Categories: Reboot

Description
  • A PowerShell script to test if a reboot is pending due to Windows Update, Component-Based Servicing, or pending file rename operations.

Code:

# Function to check if a reboot is pending
function Test-RebootPending {
  # Check Windows Update reboot pending
  $wuReboot = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update" -Name "RebootRequired" -ErrorAction SilentlyContinue)
  if ($wuReboot) {
    return $true
  }

  # Check Component-Based Servicing for pending reboot
  $cbsReboot = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing" -Name "RebootPending" -ErrorAction SilentlyContinue)
  if ($cbsReboot) {
    return $true
  }

  # Check for pending file rename operations
  $pendingFileRename = (Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" -Name "PendingFileRenameOperations" -ErrorAction SilentlyContinue)
  if ($pendingFileRename) {
    return $true
  }

  return $false
}

Update Microsoft Edge

FileName: Update-MicrosoftEdge.ps1

Categories: Application Check, Edge

Description
  • I have experienced issues updating Microsoft Edge using WinGet.
  • This method seems much more reliable

Code:

. .\Test-MicrosoftEdge
. .\Test-Administrator
. .\Exit-IfRebootPending

function Update-MicrosoftEdge {
	if (-not(Test-Administrator)) {
		Write-Host "User is not an administrator. Microsoft Edge update will be skipped." -ForegroundColor Yellow
		return
	}
	if (Test-MicrosoftEdge) {
		Write-Host "Checking for Microsoft Edge Updates"
		$updaterPath = "${env:ProgramFiles(x86)}\Microsoft\EdgeUpdate\MicrosoftEdgeUpdate.exe"
		# Arguments for silent update
		$arguments = "/silent /install appguid={56EB18F8-B008-4CBD-B6D2-8C97FE7E9062}&appname=Microsoft%20Edge&needsadmin=True"
		
		# Run the update process and wait for completion
		Start-Process -FilePath $updaterPath -ArgumentList $arguments -Wait
		
		Write-Host "Microsoft Edge has been updated successfully." -ForegroundColor Green
	} 
	Exit-IfRebootPending
}

Update Nvidia Driver

FileName: Update-Nvidia.ps1

Categories: Application Check, Nvidia Drivers

Description
  • I prefer this method to force a check and update of Nvidia drivers so I can check everythign at once and prevent the install prompt after I have all my development applications open.
  • This is a modified version of a stand along Nvidia checker and downloader. I modified it for my purposes. I will search for the link an add to this page when it is found.

Code:

. .\Test-Nvidia
. .\Test-Administrator
. .\Exit-IfRebootPending

function Update-Nvidia {
	if (-not(Test-Administrator)){
		Write-Host "User is not an administrator. Nvidia driver update will be skipped." -ForegroundColor Yellow
		return
	}
	
	if (-not(Test-Nvidia)) {
		#Write-Host "NVIDIA GPU is not detected. Skipping driver update." -ForegroundColor Yellow
		return
	}
	Exit-IfRebootPending
	# Checking if 7zip or WinRAR are installed
	# Check 7zip install path on registry
	$7zipinstalled = $false 
	
	if ((Test-path HKLM:\SOFTWARE\7-Zip\) -eq $true) {
	    $7zpath = Get-ItemProperty -path  HKLM:\SOFTWARE\7-Zip\ -Name Path
	    $7zpath = $7zpath.Path
	    $7zpathexe = $7zpath + "7z.exe"
	    if ((Test-Path $7zpathexe) -eq $true) {
	        $archiverProgram = $7zpathexe
	        $7zipinstalled = $true 
	    }    
	}
	elseif ($7zipinstalled -eq $false) {
	    if ((Test-path HKLM:\SOFTWARE\WinRAR) -eq $true) {
	        $winrarpath = Get-ItemProperty -Path HKLM:\SOFTWARE\WinRAR -Name exe64 
	        $winrarpath = $winrarpath.exe64
	        if ((Test-Path $winrarpath) -eq $true) {
	            $archiverProgram = $winrarpath
	        }
	    }
	}
	else {
	    Write-Host "Sorry, but it looks like you don't have a supported archiver."
	    Write-Host ""
	    while ($choice -notmatch "[y|n]") {
	        $choice = read-host "Would you like to install 7-Zip now? (Y/N)"
	    }
	    if ($choice -eq "y") {
	        # Download and silently install 7-zip if the user presses y
	        $7zip = "https://www.7-zip.org/a/7z1900-x64.exe"
	        $output = "$PSScriptRoot\7Zip.exe"
	        (New-Object System.Net.WebClient).DownloadFile($7zip, $output)
		
	        Start-Process "7Zip.exe" -Wait -ArgumentList "/S"
	        # Delete the installer once it completes
	        Remove-Item "$PSScriptRoot\7Zip.exe"
	    }
	    else {
	        Write-Host "Press any key to exit..."
	        $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
	        exit
	    }
	}
	
	
	
	# Checking currently installed driver version
	Write-Host "Attempting to detect currently installed driver version..."
	try {
	    $VideoController = Get-WmiObject -ClassName Win32_VideoController | Where-Object { $_.Name -match "NVIDIA" }
	    $ins_version = ($VideoController.DriverVersion.Replace('.', '')[-5..-1] -join '').insert(3, '.')
	}
	catch {
	    Write-Host -ForegroundColor Yellow "Unable to detect a compatible Nvidia device."
	    # Write-Host "Press any key to exit..."
	    # $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
	    exit
	}
	Write-Host "Installed version `t$ins_version"
	
	
	# Checking latest driver version
	$uri = 'https://gfwsl.geforce.com/services_toolkit/services/com/nvidia/services/AjaxDriverService.php' +
	'?func=DriverManualLookup' +
	'&psid=120' + # Geforce RTX 30 Series
	'&pfid=929' +  # RTX 3080
	'&osID=57' + # Windows 10 64bit
	'&languageCode=1033' + # en-US; seems to be "Windows Locale ID"[1] in decimal
	'&isWHQL=1' + # WHQL certified
	'&dch=1' + # DCH drivers (the new standard)
	'&sort1=0' + # sort: most recent first(?)
	'&numberOfResults=1' # single, most recent result is enough
	
	#[1]: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-lcid/a9eac961-e77d-41a6-90a5-ce1a8b0cdb9c
	
	$response = Invoke-WebRequest -Uri $uri -Method GET -UseBasicParsing
	$payload = $response.Content | ConvertFrom-Json
	$version =  $payload.IDS[0].downloadInfo.Version
	Write-Output "Latest version `t`t$version"
	
	
	# Comparing installed driver version to latest driver version from Nvidia
	if (!$clean -and ($version -eq $ins_version)) {
	    Write-Host "The installed version is the same as the latest version."
	    Write-Host "Press any key to exit..."
	    $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
	    exit
	}
	
	
	# Checking Windows version
	if ([Environment]::OSVersion.Version -ge (new-object 'Version' 9, 1)) {
	    $windowsVersion = "win10-win11"
	}
	else {
	    $windowsVersion = "win8-win7"
	}
	
	
	# Checking Windows bitness
	if ([Environment]::Is64BitOperatingSystem) {
	    $windowsArchitecture = "64bit"
	}
	else {
	    $windowsArchitecture = "32bit"
	}
	
	
	# Create a new temp folder NVIDIA
	$nvidiaTempFolder = "$folder\NVIDIA"
	New-Item -Path $nvidiaTempFolder -ItemType Directory 2>&1 | Out-Null
	
	
	# Generating the download link
	$url = "https://international.download.nvidia.com/Windows/$version/$version-desktop-$windowsVersion-$windowsArchitecture-international-dch-whql.exe"
	$rp_url = "https://international.download.nvidia.com/Windows/$version/$version-desktop-$windowsVersion-$windowsArchitecture-international-dch-whql-rp.exe"
	
	
	# Downloading the installer
	$dlFile = "$nvidiaTempFolder\$version.exe"
	Write-Host "Downloading the latest version to $dlFile"
	Start-BitsTransfer -Source $url -Destination $dlFile
	
	if ($?) {
	    Write-Host "Proceed..."
	}
	else {
	    Write-Host "Download failed, trying alternative RP package now..."
	    Start-BitsTransfer -Source $rp_url -Destination $dlFile
	}
	
	# Extracting setup files
	$extractFolder = "$nvidiaTempFolder\$version"
	$filesToExtract = "Display.Driver HDAudio NVI2 PhysX EULA.txt ListDevices.txt setup.cfg setup.exe"
	Write-Host "Download finished, extracting the files now..."
	
	if ($7zipinstalled) {
	    Start-Process -FilePath $archiverProgram -NoNewWindow -ArgumentList "x -bso0 -bsp1 -bse1 -aoa $dlFile $filesToExtract -o""$extractFolder""" -wait
	}
	elseif ($archiverProgram -eq $winrarpath) {
	    Start-Process -FilePath $archiverProgram -NoNewWindow -ArgumentList 'x $dlFile $extractFolder -IBCK $filesToExtract' -wait
	}
	else {
	    Write-Host "Something went wrong. No archive program detected. This should not happen."
	    Write-Host "Press any key to exit..."
	    $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
	    exit
	}
	
	
	# Remove unneeded dependencies from setup.cfg
	(Get-Content "$extractFolder\setup.cfg") | Where-Object { $_ -notmatch 'name="\${{(EulaHtmlFile|FunctionalConsentFile|PrivacyPolicyFile)}}' } | Set-Content "$extractFolder\setup.cfg" -Encoding UTF8 -Force
	
	
	# Installing drivers
	Write-Host "Installing Nvidia drivers now..."
	$install_args = "-passive -noreboot -noeula -nofinish -s"
	if ($clean) {
	    $install_args = $install_args + " -clean"
	}
	Start-Process -FilePath "$extractFolder\setup.exe" -ArgumentList $install_args -wait
	
	# Cleaning up downloaded files
	Write-Host "Deleting downloaded files"
	Remove-Item $nvidiaTempFolder -Recurse -Force
	
	Exit-IfRebootPending
		
}

Update Visual Studio Code Extensions

FileName: Update-VsCodeExtensions.ps1

Categories: Application Check, VS Code

Description
  • This script verifies the installation of Visual Studio Code to prevent the extension update from running
  • The text from the actual update process is suppressed to clean up the script. Enable if verbose text is desired.

Code:

. .\Test-ApplicationInstalled
function Update-VsCodeExtensions {
	if (-not(Test-ApplicationInstalled -appId "Microsoft.VisualStudioCode")) {
		Write-Host "Visual Studio Code is not installed. Skipping extension update." -ForegroundColor Yellow
		return
	}
	
	if (Test-ApplicationInstalled -appId "Microsoft.VisualStudioCode") {

		code --update-extensions
		# Get the list of installed extensions
		$extensions = code --list-extensions

		# Update each extension
		foreach ($extension in $extensions) {
			#Write-Host "Updating Visual Studio Code extension: $extension" -ForegroundColor Blue
			code --install-extension $extension --force | Out-Null
		}
	}
}

Update Windows Defender Anti-Virus

FileName: Update-Defender.ps1

Categories: Application Check, Windows Defender

Description
  • Update Windows Defender
  • Run Quick Scan

Code:

. .\Test-DefenderActive
. .\Test-Administrator
. .\Exit-IfRebootPending
function Update-Defender {
	if (-not(Test-Administrator)) {
		Write-Host "User is not an administrator. Windows Defender update will be skipped." -ForegroundColor Yellow
		return
	}
	if (Test-DefenderActive) {
		# Store current path in a variable
		$currentPath = Get-Location
		Write-Host "Updating Windows Defender..."
		#This update seems to only work from the root of the drive
		Set-Location \
		Write-Host "Windows Defender Update"
		Update-MpSignature
		Write-Host "Windows Defender Quick Scan"
		Start-MpScan -ScanType QuickScan
		Write-Host "Quick scan completed."
	
	}
	#Restore original location
	Set-Location -Path $currentPath
	Exit-IfRebootPending
}

Verify if a list of applications are installed

FileName: Write-InstallCheck.ps1

Categories: WinGet, Application Check

Description
  • Uses WinGet to check if an application is installed based on its application ID. This function can be used to verify the presence of specific software before attempting installation or performing other actions.

Code:

. .\Test-DefenderActive
. .\Test-Winget
. .\Test-MicrosoftEdge
. .\Test-Nvidia
. .\Test-ApplicationInstalled


function Write-InstallCheck {
  Write-Host "Install Check:"
  Write-Host "--------------------"
  if (Test-Winget) {
    Write-Host "Winget: PRESENT" -ForegroundColor Green
  } else {
    Write-Host "Winget: install to be attempted" -ForegroundColor Blue
  }
        
  if (Test-Winget) {
    if (Test-ApplicationInstalled -appId "Microsoft.PowerShell") {
      Write-Host "PowerShell: PRESENT" -ForegroundColor Green
    } else {
      Write-Host "PowerShell: install to be attempted" -ForegroundColor Blue
    }
    if (Test-ApplicationInstalled -appId "Microsoft.WindowsTerminal") {
      Write-Host "Windows Terminal: PRESENT" -ForegroundColor Green
    } else {
    Write-Host "Windows Terminal: install to be attempted" -ForegroundColor Blue
    }
    if (Test-ApplicationInstalled -appId "Git.Git") {
      Write-Host "Git: PRESENT" -ForegroundColor Green
    } else {
      Write-Host "Git: install to be attempted" -ForegroundColor Blue
    }
    if (Test-ApplicationInstalled -appId "7zip.7zip") {
      Write-Host "7-Zip: PRESENT" -ForegroundColor Green
    } else {
      Write-Host "7-Zip: install to be attempted" -ForegroundColor Blue
    }
    if (Test-ApplicationInstalled -appId "Microsoft.VisualStudioCode") {
      Write-Host "Visual Studio Code: PRESENT" -ForegroundColor Green
    } else {
      Write-Host "Visual Studio Code: install to be attempted" -ForegroundColor Blue
    }
    if (Test-ApplicationInstalled -appId "XP89DCGQ3K6VLD") {
      Write-Host "Windows PowerToys: PRESENT" -ForegroundColor Green
    } else {
      Write-Host "Windows PowerToys: install to be attempted" -ForegroundColor Blue
    }
  }
    Write-Host "--------------------"
}

Verify WinGet Is Installed

FileName: Test_WinGet.ps1

Categories: WinGet

Description
  • Verify if WinGet is installed on the system.

Code:

function Test-Winget {
  try {
    winget --version
  }
  catch {
    return $false
  }
  return $true
}