Updating password-protected software

By | 22nd May 2021

PowerShell script for updating a password-protected app. Main purpose using for WorkGroup computers.

$software = "Data Protection Agent";  # example for test
$software_version_new = "3.4.10020.0";
$software_version_old = "3.4.9*";
$install_path = "W:\PUBLIC FOLDER\PeterW\Link to installer"; # example
$computername = $env:COMPUTERNAME;
$latest = (Get-WmiObject Win32_Product -ComputerName $computername | Where { $_.Name -match $software -and $_.Version -eq $software_version_new })
$update = (Get-WmiObject Win32_Product -ComputerName $computername | Where { $_.Name -match $software -and $_.Version -Like $software_version_old })

If(-Not ($latest) -and -Not ($update)) {
	Write-Host $software "is NOT installed on" $computername;
    Write-Host 'Press any key to INSTALL';  
    $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
    Start-Process -File $install_path; # -Verb runAs -ArgumentList '/s','/v"/qn"'
}

elseif(-Not ($latest) -and ($update)) {
	Write-Host "The old version of " $software "is installed on" $computername;
    Write-Host 'Press any key to UNINSTALL';  
    $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
    Get-Command -Type Cmdlet | MsiExec.exe /x "{27731AE4-2248-42BE-8580-5AABE5696053}" /qn UNINSTALL_PASSWORD=Secret # Example of password
}

else {
	Write-Host "The latest version of: " $software " is installed on" $computername
    Write-Host -NoNewLine 'Press any key to CLOSE window...';
    $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
}