Skip to content

Instantly share code, notes, and snippets.

@gwblok
Created December 23, 2019 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gwblok/7c3e7db8731f9961a4dc85386419444f to your computer and use it in GitHub Desktop.
Save gwblok/7c3e7db8731f9961a4dc85386419444f to your computer and use it in GitHub Desktop.
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 {
[CmdletBinding()]
Param (
[Parameter(Mandatory=$false)]
$Message,
[Parameter(Mandatory=$false)]
$ErrorMessage,
[Parameter(Mandatory=$false)]
$Component = "HP Script Library Installer",
[Parameter(Mandatory=$false)]
[int]$Type,
[Parameter(Mandatory=$true)]
$LogFile
)
<#
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 = "https://ftp.hp.com/pub/caps-softpaq/cmit/release/cmsl/hp-cmsl-latest.exe"
$XMLURL = "ftp://ftp.hp.com/pub/caps-softpaq/cmit/release/cmsl/hpcmsl.xml"
$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 proxy-garytown.com -Port 8080).PingSucceeded -eq $True)
{
$UseProxy = $true
$ProxyServer = "http://proxy-garytown.com:8080"
$BitsProxyList = @("192.168.1.176:8080, 168.33.22.169:8080, 111.222.214.218.21:8080")
}
Else
{
$ProxyServer = $null
}
#>
If(Test-Path $XMLPath){Remove-Item -Path $XMLPath -Force}
Invoke-WebRequest -Uri $XMLURL -OutFile $XMLPath -UseBasicParsing -Proxy $ProxyServer
[int32]$n=1
While(!(Test-Path $XMLPath) -and $n -lt '3')
{
Invoke-WebRequest -Uri $XMLURL -OutFile $XMLPath -UseBasicParsing -Proxy $ProxyServer
$n++
}
[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
}
else
{
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