Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Check HPCMSL Version
#This will download the latest version of the HP Script Library, Install it and confirm it's installed.
#region: CMTraceLog Function formats logging in CMTrace style
function CMTraceLog {
Param (
$Component = "HP Script Library Installer",
Type: 1 = Normal, 2 = Warning (yellow), 3 = Error (red)
$Time = Get-Date -Format "HH:mm:ss.ffffff"
$Date = Get-Date -Format "MM-dd-yyyy"
if ($ErrorMessage -ne $null) {$Type = 3}
if ($Component -eq $null) {$Component = " "}
if ($Type -eq $null) {$Type = 1}
$LogMessage = "<![LOG[$Message $ErrorMessage" + "]LOG]!><time=`"$Time`" date=`"$Date`" component=`"$Component`" context=`"`" type=`"$Type`" thread=`"`" file=`"`">"
$LogMessage | Out-File -Append -Encoding UTF8 -FilePath $LogFile
$URL = ""
$XMLURL = ""
$XMLPath = "$PSScriptRoot\hpcmsl.xml"
$LogFile = "$($env:Temp)\HPScriptLibInstaller.log"
$HPScriptLibVer = $null
$scriptName = $MyInvocation.MyCommand.Name
$DownloadPath = $env:TEMP
# Download HP XML
<# If you use a Proxy, add that info here
if ((Test-NetConnection -Port 8080).PingSucceeded -eq $True)
$UseProxy = $true
$ProxyServer = ""
$BitsProxyList = @(",,")
$ProxyServer = $null
If(Test-Path $XMLPath){Remove-Item -Path $XMLPath -Force}
Invoke-WebRequest -Uri $XMLURL -OutFile $XMLPath -UseBasicParsing -Proxy $ProxyServer
While(!(Test-Path $XMLPath) -and $n -lt '3')
Invoke-WebRequest -Uri $XMLURL -OutFile $XMLPath -UseBasicParsing -Proxy $ProxyServer
[xml]$XML = Get-Content $XMLPath -Verbose
$Packages = $XML.'hp-update-catalog'.product.package
$LatestVersion = ($Packages | Measure-Object -Property "Version" -Maximum).Maximum
#Check if already installed.. and if current
$HPScriptLibVer = (Get-WmiObject -Namespace 'root\cimv2\sms' -Query "SELECT ProductVersion FROM SMS_InstalledSoftware where ARPDisplayName like 'HP Client Management Script Library'").ProductVersion
if ($HPScriptLibVer -eq $LatestVersion)
Write-Output "Compliant"
#CMTraceLog -Message "Already Current running version $($HPScriptLibVer)" -Type 1 -LogFile $LogFile
$AlreadyCurrent = $true
Write-Output "Has $($HPScriptLibVer), Needs: $($LatestVersion)"
CMTraceLog -Message "Does not have the Current Version $($LatestVersion) Installed" -Type 1 -LogFile $LogFile
$AlreadyCurrent = $false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.