Lenovo System Update installer

Topics: Archive - Deployment Scripts, Archive - General
Apr 17, 2014 at 2:24 PM
Edited Apr 23, 2014 at 5:23 PM
I'm new to this product, and this will be the third application of many that I will be using it with. I'm trying to install Lenovo's System Update, but first I would like it to detect the OS version - since Windows 8 does not have .Net Fx 3.5 enabled by default and it is a pre-requisite. I would like it to detect if it is Windows 8 or higher, if .Net Fx 3.5 is enabled, if not Enable it and then install LSU. If less than Windows 8, just install LSU. I've been having problems getting it to work, and could use some advise, I am quite new to PowerShell, as I am transitioning from batch deployments.

Here is what I have so far.

Edit: This is now the Final Working Script! Thank you Sintaxasn (Dan) for your assistance.
Param (
    [ValidateSet("Install","Uninstall")] 
    [string] $DeploymentType = "Install",
    [ValidateSet("Interactive","Silent","NonInteractive")]
    [string] $DeployMode = "Interactive",
    [switch] $AllowRebootPassThru = $true,
    [switch] $TerminalServerMode = $false
)

#*===============================================
#* VARIABLE DECLARATION
Try {
#*===============================================

#*===============================================
# Variables: Application

$appVendor = "Lenovo"
$appName = "System Update"
$appVersion = "5.05.0008"
$appArch = ""
$appLang = "EN"
$appRevision = "01"
$appScriptVersion = "1.0.0"
$appScriptDate = "04/15/2014"
$appScriptAuthor = ""

# Custom Variables: Lenovo System Update

$suInstaller = "systemupdate505-02-14-2014.exe"
$suRemove = "{25C64847-B900-48AD-A164-1B4F9B774650}"
$suPath = "HKLM:\Software\Wow6432Node\Lenovo\System Update"
$suVersion = Get-Item $suPath -ErrorAction SilentlyContinue | Get-ItemProperty | Select "Version" -ExpandProperty "Version"

$osVersion = (Get-WmiObject -Class Win32_OperatingSystem).version
$netFX = (Get-WindowsOptionalFeature -Online -FeatureName NetFx3).State 

#*===============================================
# Variables: Script - Do not modify this section

$deployAppScriptFriendlyName = "Deploy Application"
$deployAppScriptVersion = [version]"3.1.0"
$deployAppScriptDate = "02/25/2013"
$deployAppScriptParameters = $psBoundParameters

# Variables: Environment
$scriptDirectory = Split-Path -Parent $MyInvocation.MyCommand.Definition
# Dot source the App Deploy Toolkit Functions
."$scriptDirectory\AppDeployToolkit\AppDeployToolkitMain.ps1"

#*===============================================
#* END VARIABLE DECLARATION
#*===============================================

#*===============================================
#* PRE-INSTALLATION
If ($deploymentType -ne "uninstall") { $installPhase = "Pre-Installation"
#*===============================================

    # Show Welcome Message, close Internet Explorer if required, allow up to 3 deferrals, verify there is enough disk space to complete the install and persist the prompt
    Show-InstallationWelcome -CloseApps "iexplore" -AllowDefer -DeferTimes 3 -CheckDiskSpace -PersistPrompt -MinimizeWindows 0

    # Show Progress Message (with the default message)
    Show-InstallationProgress

    # Perform pre-installation tasks here

#*===============================================
#* INSTALLATION 
$installPhase = "Installation"
#*===============================================

    # Perform installation tasks here

    # Check if OS version is Windows 8 or greater
    If (($osVersion -ge 6.2)-and($suVersion -lt $appVersion)) {
        # Check is .Net Framework Feature is Enabled for System Update Pre-Req, if not then Enable then install System Update or Install if already Enabled.
        If ($netFX -eq "Disabled"){
        Write-Log ".Net Framework 3.5 Not Enabled - Installing Feature."
        Show-InstallationProgress "Installing .Net Framework 3.5 Pre-Requisite"
        # Enable .Net framework 3.5 Method #1 (Windows Update) Enable-WindowsOptionalFeature –Online –FeatureName NetFx3 –All
        # Enable .Net framework 3.5 Method #2 (Source Dir) Enable-WindowsOptionalFeature –Online –FeatureName NetFx3 –All -LimitAccess -Source $dirSupportFiles\sources\sxs
        Enable-WindowsOptionalFeature –Online –FeatureName NetFx3 –All -LimitAccess -Source $dirSupportFiles\sources\sxs
        Write-Log "Installing Lenovo System update $appVersion"
        Show-InstallationProgress "Installing Latest Lenovo System Update version $appVersion"
        Execute-Process -FilePath $suInstaller -Arguments "-s -a /s /v/qn CREATESHORTCUT=1 REBOOT=R"}
        
        
        # If .Net framework 3.5 Enabled, and Lenovo System Update is below current installer version - Run Installer
        elseif ($netFX -eq "Enabled"){
        Write-Log "Installing Lenovo System update"
        Show-InstallationProgress "Installing Latest Lenovo System Update version"
        Execute-Process -FilePath $suInstaller -Arguments "-s -a /s /v/qn CREATESHORTCUT=1 REBOOT=R"}
    }
    # Check if OS version is less than Windows 8
    elseif (($osVersion -lt 6.2)-and($suVersion -lt $appVersion)) {
        Write-Log "Installing Lenovo System update $appVersion"
        Show-InstallationProgress "Installing Latest Lenovo System Update version $appVersion"
        Execute-Process -FilePath $suInstaller -Arguments "-s -a /s /v/qn CREATESHORTCUT=1 REBOOT=R"
    }   
    else {
        Show-InstallationProgress "Updated Version Detected"
        Write-Log "$envComputerName has the most up to date version of System Update according to installer settings - $appVersion"
        Show-DialogBox -Title "Version $appVersion Compliant" -Text "Your Lenovo System Update is already at the latest version."
    }
    
#*===============================================
#* POST-INSTALLATION
$installPhase = "Post-Installation"
#*===============================================

    # Perform post-installation tasks here
    Write-Log "Updating custom Registry entries"
    Show-InstallationProgress "Updating Registry entries"
    # UCSettings
    Set-RegistryKey -Key "HKLM\SOFTWARE\Wow6432Node\Lenovo\System Update\Preferences\UCSettings\Billboard" -Name "LiveFeed" -Value "" -Type String
    
    # User Settings
    Set-RegistryKey -Key "HKLM\SOFTWARE\Wow6432Node\Lenovo\System Update\Preferences\UserSettings\General" -Name "DebugEnable" -Value "YES" -Type String
    Set-RegistryKey -Key "HKLM\SOFTWARE\Wow6432Node\Lenovo\System Update\Preferences\UserSettings\General" -Name "DisplayInformationScreen" -Value "NO" -Type String
    Set-RegistryKey -Key "HKLM\SOFTWARE\Wow6432Node\Lenovo\System Update\Preferences\UserSettings\General" -Name "DisplayLicenseNotice" -Value "NO" -Type String
    Set-RegistryKey -Key "HKLM\SOFTWARE\Wow6432Node\Lenovo\System Update\Preferences\UserSettings\General" -Name "DisplayLicenseNoticeSU" -Value "NO" -Type String
    Set-RegistryKey -Key "HKLM\SOFTWARE\Wow6432Node\Lenovo\System Update\Preferences\UserSettings\General" -Name "IgnoreLocalLicense" -Value "YES" -Type String
    Set-RegistryKey -Key "HKLM\SOFTWARE\Wow6432Node\Lenovo\System Update\Preferences\UserSettings\General" -Name "IgnoreRMLicCRCSize" -Value "NO" -Type String
    Set-RegistryKey -Key "HKLM\SOFTWARE\Wow6432Node\Lenovo\System Update\Preferences\UserSettings\Scheduler" -Name "SchedulerLock" -Value "HIDE" -Type String
    Set-RegistryKey -Key "HKLM\SOFTWARE\Wow6432Node\Lenovo\System Update\Preferences\UserSettings\Scheduler" -Name "NotifyOptions" -Value "DOWNLOADANDINSTALL-INCLUDEREBOOT" -Type String

    
#*===============================================
#* UNINSTALLATION
} ElseIf ($deploymentType -eq "uninstall") { $installPhase = "Uninstallation"
#*===============================================

    # Show Welcome Message, close Internet Explorer if required with a 60 second countdown before automatically closing
    Show-InstallationWelcome -CloseApps "iexplore" -CloseAppsCountdown "60"

    # Show Progress Message (with the default message)
    Show-InstallationProgress

    # Perform uninstallation tasks here
    Execute-MSI -Action Uninstall -Path $suRemove /qn

#*===============================================
#* END SCRIPT BODY
} } Catch { $exceptionMessage = "$($_.Exception.Message) `($($_.ScriptStackTrace)`)"; Write-Log "$exceptionMessage"; Show-DialogBox -Text $exceptionMessage -Icon "Stop"; Exit-Script -ExitCode 1 } # Catch any errors in this script 
Exit-Script -ExitCode 0 # Otherwise call the Exit-Script function to perform final cleanup operations
#*===============================================
Apr 17, 2014 at 3:22 PM
Edited Apr 17, 2014 at 7:48 PM
Just an update in my troubleshooting here... I removed the $ before the Enabled/Disabled for the netFX check and that now works properly. However, I am not running into an issue with the
-Arguments "-s -a /s /v" /qn CREATESHORTCUT=1 REBOOT=R
portion of the script... as I am converting this from batch the above switches are called exactly as displayed minus the -Arguments obviously. I know the " is throwing it off and I've also tried separating each to display as follows.
-Arguments "-s, -a, /s, /v" /qn CREATESHORTCUT=1 REBOOT=R"
Thank you

Edit 1:

It would seem I have figured out the issue with the -Arguments, the following works:
-Arguments "-s -a /s /v/qn CREATESHORTCUT=1 REBOOT=R"
Now Im trying to figure out how to establish whether or not it is currently installed, and if so, what version? Is it the current? If not - install the current according to the script.

Edit 2:

I think I've come up with a viable solution, Im just curious as to whether or not there may be a better method. Here is what I have right now.
#*===============================================

    # Perform installation tasks here

#*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    #   Custom Variables
# Get the OS version
$osVersion = [version]$($envOS.version)
# Get the .NetFx 3.5 status
$netFX = (Get-WindowsOptionalFeature -Online -FeatureName NetFx3).State
# Establishing the Lenovo System Update Version variable
$suVersion = (Get-ItemProperty "HKLM:\Software\Wow6432Node\Lenovo\System Update" -Name Version).Version
#*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   

    # Check if OS version is Windows 8 or greater
    If ($osVersion -ge 6.2)-and($suVersion -lt 5.05.0008)) {
        # Check is .Net Framework Feature is Enabled for System Update Pre-Req, if not then Enable then install System Update or Install if already Enabled.
        If ($netFX -eq "Disabled"){
        Enable-WindowsOptionalFeature –Online –FeatureName NetFx3 –All -LimitAccess -Source $dirSupportFiles\sources\sxs
        Execute-Process -FilePath "systemupdate505-02-14-2014.exe" -Arguments "-s -a /s /v/qn CREATESHORTCUT=1 REBOOT=R"
        }
        # Enable .Net framework 3.5 Method #1 (Windows Update) Enable-WindowsOptionalFeature –Online –FeatureName NetFx3 –All
        # Enable .Net framework 3.5 Method #2 (Source Dir) Enable-WindowsOptionalFeature –Online –FeatureName NetFx3 –All -LimitAccess -Source $dirSupportFiles\sources\sxs
        
        # If .Net framework 3.5 Enabled, and Lenovo System Update is below current installer version - Run Installer
        elseif ($netFX -eq "Enabled"){Execute-Process -FilePath "systemupdate505-02-14-2014.exe" -Arguments "-s -a /s /v/qn CREATESHORTCUT=1 REBOOT=R"}
    }
    # Check if OS version is less than Windows 8
    elseif (($osVersion -lt 6.2)-and($suVersion -lt 5.05.0008)) {
        Execute-Process -FilePath "systemupdate505-02-14-2014.exe" -Arguments "-s -a /s /v/qn CREATESHORTCUT=1 REBOOT=R"
    }   
    else
        Show-DialogBox -Title "Version Compliant" -Text "Your Lenovo System Update is already at the latest version."
Now I'm looking to add logging to each of the processes occurring above, as well updating of the Show-InstallationProgress for each point.

I will continue to keep this updated with my findings
Coordinator
Apr 18, 2014 at 3:02 PM
Hey there.

Looks pretty good to me. Just FYI, to open quotes inside quotes, prefix the quote (") with an apostraphe ('). So your original line would be:
Execute-Process -FilePath "systemupdate505-02-14-2014.exe" -Arguments "-s -a /s /v'"/qn CREATESHORTCUT=1 REBOOT=R'""
Dan.
Apr 21, 2014 at 12:46 PM
Thank you Dan,

That's very useful!

However, now I'm having an issue where the script will not run at all and I receive no error notifications. Perhaps you wouldn't mind helping me out, here is exactly what I have.
#*===============================================
#* VARIABLE DECLARATION
Try {
#*===============================================

#*===============================================
# Variables: Application

$appVendor = "Lenovo"
$appName = "System Update"
$appVersion = "5.05.0008"
$appArch = ""
$appLang = "EN"
$appRevision = "01"
$appScriptVersion = "1.0.0"
$appScriptDate = "04/15/2014"
$appScriptAuthor = ""

#*===============================================
# Variables: Script - Do not modify this section

$deployAppScriptFriendlyName = "Deploy Application"
$deployAppScriptVersion = [version]"3.1.0"
$deployAppScriptDate = "02/25/2013"
$deployAppScriptParameters = $psBoundParameters

# Variables: Environment
$scriptDirectory = Split-Path -Parent $MyInvocation.MyCommand.Definition
# Dot source the App Deploy Toolkit Functions
."$scriptDirectory\AppDeployToolkit\AppDeployToolkitMain.ps1"

#*===============================================
#* END VARIABLE DECLARATION
#*===============================================

#*===============================================
#* PRE-INSTALLATION
If ($deploymentType -ne "uninstall") { $installPhase = "Pre-Installation"
#*===============================================

    # Show Welcome Message, close Internet Explorer if required, allow up to 3 deferrals, verify there is enough disk space to complete the install and persist the prompt
    Show-InstallationWelcome -CloseApps "iexplore" -AllowDefer -DeferTimes 3 -CheckDiskSpace -PersistPrompt -MinimizeWindows 0

    # Show Progress Message (with the default message)
    Show-InstallationProgress

    # Perform pre-installation tasks here

#*===============================================
#* INSTALLATION 
$installPhase = "Installation"
#*===============================================

    # Perform installation tasks here

#*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    #   Custom Variables
# Get the OS version
$osVersion = [version]$($envOS.version)
# Get the .NetFx 3.5 status
$netFX = (Get-WindowsOptionalFeature -Online -FeatureName NetFx3).State 
# Establishing the Lenovo System Update Version variable
$suVersion = (Get-ItemProperty "HKLM:\Software\Wow6432Node\Lenovo\System Update" -Name Version).Version
#*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   

    # Check if OS version is Windows 8 or greater
    If (($osVersion -ge 6.2)-and($suVersion -lt $"$appVersion")) {
        # Check is .Net Framework Feature is Enabled for System Update Pre-Req, if not then Enable then install System Update or Install if already Enabled.
        If ($netFX -eq "Disabled"){
        Write-Log ".Net Framework 3.5 Not Enabled - Installing Feature."
        Show-InstallationProgress "Installing .Net Framework 3.5 Pre-Requisite"
        Enable-WindowsOptionalFeature –Online –FeatureName NetFx3 –All -LimitAccess -Source $dirSupportFiles\sources\sxs
        Write-Log "Installing Lenovo System update $appVersion"
        Show-InstallationProgress "Installing Latest Lenovo System Update version $appVersion"
        Execute-Process -FilePath "systemupdate505-02-14-2014.exe" -Arguments "-s -a /s /v/qn CREATESHORTCUT=1 REBOOT=R"}
        # Enable .Net framework 3.5 Method #1 (Windows Update) Enable-WindowsOptionalFeature –Online –FeatureName NetFx3 –All
        # Enable .Net framework 3.5 Method #2 (Source Dir) Enable-WindowsOptionalFeature –Online –FeatureName NetFx3 –All -LimitAccess -Source $dirSupportFiles\sources\sxs
        
        # If .Net framework 3.5 Enabled, and Lenovo System Update is below current installer version - Run Installer
        elseif ($netFX -eq "Enabled"){
        Write-Log "Installing Lenovo System update"
        Show-InstallationProgress "Installing Latest Lenovo System Update version"
        Execute-Process -FilePath "systemupdate505-02-14-2014.exe" -Arguments "-s -a /s /v/qn CREATESHORTCUT=1 REBOOT=R"}
    }
    # Check if OS version is less than Windows 8
    elseif (($osVersion -lt 6.2)-and($suVersion -lt $"$appVersion")) {
        Write-Log "Installing Lenovo System update $appVersion"
        Show-InstallationProgress "Installing Latest Lenovo System Update version $appVersion"
        Execute-Process -FilePath "systemupdate505-02-14-2014.exe" -Arguments "-s -a /s /v/qn CREATESHORTCUT=1 REBOOT=R"
    }   
    
    
#*===============================================
#* POST-INSTALLATION
$installPhase = "Post-Installation"
#*===============================================

    # Perform post-installation tasks here
    
    #If ($suVersion -lt $"$appVersion") {
    Write-Log "Updating custom Registry entries"
    Show-InstallationProgress "Updating Registry entries"
    # UCSettings
    Set-RegistryKey -Key "HKLM\SOFTWARE\Wow6432Node\Lenovo\System Update\Preferences\UCSettings\Billboard" -Name "LiveFeed" -Value "" -Type String
    
    # User Settings
    Set-RegistryKey -Key "HKLM\SOFTWARE\Wow6432Node\Lenovo\System Update\Preferences\UserSettings\General" -Name "DebugEnable" -Value "YES" -Type String
    Set-RegistryKey -Key "HKLM\SOFTWARE\Wow6432Node\Lenovo\System Update\Preferences\UserSettings\General" -Name "DisplayInformationScreen" -Value "NO" -Type String
    Set-RegistryKey -Key "HKLM\SOFTWARE\Wow6432Node\Lenovo\System Update\Preferences\UserSettings\General" -Name "DisplayLicenseNotice" -Value "NO" -Type String
    Set-RegistryKey -Key "HKLM\SOFTWARE\Wow6432Node\Lenovo\System Update\Preferences\UserSettings\General" -Name "DisplayLicenseNoticeSU" -Value "NO" -Type String
    Set-RegistryKey -Key "HKLM\SOFTWARE\Wow6432Node\Lenovo\System Update\Preferences\UserSettings\General" -Name "IgnoreLocalLicense" -Value "YES" -Type String
    Set-RegistryKey -Key "HKLM\SOFTWARE\Wow6432Node\Lenovo\System Update\Preferences\UserSettings\General" -Name "IgnoreRMLicCRCSize" -Value "NO" -Type String
    Set-RegistryKey -Key "HKLM\SOFTWARE\Wow6432Node\Lenovo\System Update\Preferences\UserSettings\Scheduler" -Name "SchedulerLock" -Value "HIDE" -Type String
    Set-RegistryKey -Key "HKLM\SOFTWARE\Wow6432Node\Lenovo\System Update\Preferences\UserSettings\Scheduler" -Name "NotifyOptions" -Value "DOWNLOADANDINSTALL-INCLUDEREBOOT" -Type String
    
    else 
    {
        Show-DialogBox -Title "Version $appVersion Compliant" -Text "Your Lenovo System Update is already at the latest version."
    }
    
#*===============================================
#* UNINSTALLATION
} ElseIf ($deploymentType -eq "uninstall") { $installPhase = "Uninstallation"
#*===============================================

    # Show Welcome Message, close Internet Explorer if required with a 60 second countdown before automatically closing
    Show-InstallationWelcome -CloseApps "iexplore" -CloseAppsCountdown "60"

    # Show Progress Message (with the default message)
    Show-InstallationProgress

    # Perform uninstallation tasks here
    Execute-MSI -Action Uninstall -Path "{25C64847-B900-48AD-A164-1B4F9B774650}" /qn
Coordinator
Apr 22, 2014 at 3:53 PM
You seem to be missing some of the script, which would cause the script to fail (incomplete Try / Catch, missing includes at the top). This would explain a failure in the script itself and an inability to report errors.

You can verify this yourself by opening PowerShell as an Administrator and running Deploy-Application.ps1 directly. This should give you the error and line number it's occurring on.

Dan
Apr 23, 2014 at 5:25 PM
I got all the bugs worked out, and Edited my initial post to display the full working script.

Thank you Dan, I also have a few other scripts that I'll be posting to share with others. I'm sure I'll be active on here sharing and asking questions now that I've opened the door to this product and am enjoying what it has to offer.
Coordinator
Apr 23, 2014 at 5:56 PM
Excellent, great work! :)