Hi All,
I created PowerShell went to auto download adobe reader and auto install, but always show exitcode:87
My Script:
####################################
# Catch Local File Cunnect Version #
####################################
$Path = "D:\Iverson\PSScript\Reader"
$Reader_Path = Get-ChildItem -Path $Path -Recurse -File | Where-Object { $_.Name -like "AcroRdrDCUpd*" }
$Reader_Path2 = "D:\Iverson\PSScript\Reader\$Reader_Path"
$fileName = (Get-Item $Reader_Path2).Name
$File_Current_Version = [regex]::Match($fileName, '\d+').Value
####################################
# Get Web and File version #
####################################
Import-Module -ErrorAction Stop \\cifstp01\TP\IT\Networking\PS_SCRIPT\PowerHTML
$res = Invoke-WebRequest -Uri "https://www.adobe.com/devnet-docs/acrobatetk/tools/ReleaseNotesDC/continuous/dccontinuousmar2023.html#dccontinuousmartwentytwentythree" -UseBasicParsing
$htm = ConvertFrom-Html -Content $res
$p = $htm.SelectNodes('/html/body/div/section/div[2]/div/div[2]/div/div/h1')
$p2 = $htm.SelectNodes('/html/body/div/section/div[2]/div/div[2]/div/div/div[2]/table[1]/tbody/tr[3]/td[3]/p/a')
$Web_Current_version = $p.InnerText.Substring(0,12)
$version = $p2.InnerText.Substring(12,10)
$SOFTNAME = $p2.InnerText
$tt= "C:\temp\AcroRdrDCUpd$($version)_MUI.msp"
####################################
# Check Web version and notify #
####################################
IF ($Web_Current_version.count -eq 0) {
$Report = "Cannnot find Adobe Reader version in Web Site"
Send-MailMessage -From "TP_SYSMGR@Vis.com" -To "iverson.hsieh@Vis.com" -cc "iverson.hsieh@Vis.com" -Subject "Adobe Reader get version error" -Body $Report -BodyAsHtml -SmtpServer "hubmv01.corp.vis.com"
}
IF ($version -ne $File_Current_Version) {
$Days = "10"
$CutoffDate = (Get-Date).AddDays(-$Days)
Get-ChildItem -Path $Path -Recurse -File | Where-Object { ($_.Name -like "AcroRdrDCUpd*")} | Remove-Item -Recurse –Force -Verbose
$Download = "D:\Iverson\PSScript\Reader\AcroRdrDCUpd$($version)_MUI.msp"
Invoke-WebRequest "https://ardownload2.adobe.com/pub/adobe/reader/win/AcrobatDC/$version/AcroRdrDCUpd$($version)_MUI.msp" -OutFile $Download
$Report = "Adobe Reader has new version"
Send-MailMessage -From "TP_SYSMGR@Vis.com" -To "iverson.hsieh@Vis.com" -cc "iverson.hsieh@Vis.com" -Subject "Adobe Reader has new version" -Body $Report -BodyAsHtml -SmtpServer "hubmv01.corp.vis.com"
$Path = "D:\Iverson\PSScript\Reader"
}
##########################
# Scriptblock #
##########################
$Scriptblock = {
Param (
$ComputerName,
$Web_Current_version,
$Reader_Ver,
$Reader_Install_Date
)
$ErrorActionPreference = "Stop"
$Cur_Date = Get-Date
$Reader_Version = "" | Select-Object ComputerName, DisplayName, DisplayVersion, Publisher, InstallDate, Check_Date, IP, Remark
$Reader_Version.ComputerName = $ComputerName
$Reader_Version.DisplayName = "Adobe Acrobat Reader MUI"
$Reader_Version.DisplayVersion = $Reader_Ver
$Reader_Version.Publisher = "Adobe"
$Reader_Version.InstallDate = $Reader_Install_Date
$Reader_Version.Check_Date = $Cur_Date
Try {
$DNS_IP = (Get-ADComputer $ComputerName -Properties IPv4Address).IPv4Address
$Reader_Version.IP = $DNS_IP
}
Catch {
$Reader_Version.Remark = "Get-ADComputer IP Failed"
Return $Reader_Version
}
IF(-not (Test-Connection -ComputerName $ComputerName -Quiet -count 1)) {
$Reader_Version.Remark = "Offline"
Return $Reader_Version
}
Try {
$PC_IP = (Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName $ComputerName -ea Stop -ev err).ipaddress | Where-Object {$_ -like "10.2*"}
}
Catch {
$Reader_Version.Remark = "Check PC_IP Failed : " + $err.ErrorRecord.Exception.message
Return $Reader_Version
}
IF(-not ($ComputerName -eq ([System.Net.Dns]::GetHostByAddress($PC_IP).Hostname).Split('.')[0])) {
$Reader_Version.Remark = "DNS_IP don't mtch PC_IP"
Return $Reader_Version
}
Try {
$PC_Reader_Version = Invoke-Command -Computer $ComputerName {
$INSTALLED = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate
$INSTALLED += Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate
$INSTALLED | ?{ $_.DisplayName -eq 'Adobe Acrobat Reader MUI' } | sort-object -Property DisplayName -Unique
} -ea Stop -ev err
IF ($PC_Reader_Version.DisplayVersion -ne $Web_Current_version) {
$path = "\\$ComputerName\C$\temp"
If(!(test-path $path)) {
New-Item -ItemType Directory -Force -Path $path -ea Stop -ev err
}
Copy-Item -Path "D:\Iverson\PSScript\Reader\$SOFTNAME" -Destination "\\$ComputerName\c$\temp\$SOFTNAME" -Force -ea Stop -ev err
#$Result = Invoke-Command -computername $ComputerName -ScriptBlock {(Start-Process "msiexec" -ArgumentList "/p C:\temp\$SOFTNAME /quiet /norestart" -Wait -Passthru).ExitCode}
$Result = Invoke-Command -ComputerName $ComputerName -ScriptBlock {
param($tt)
(Start-Process msiexec "/p $tt /quiet /norestart" -Wait -PassThru).ExitCode
} -ArgumentList $tt
IF ($Result -ne 0) {
$Reader_Version.Remark = "Update Failed, returncode : " + $Result
Return $Reader_Version
}
else{
$Reader_Version.Remark = "Update Successfully"
Return $Reader_Version
}
Remove-item "\\$ComputerName\C$\temp\$SOFTNAME" -Force -ea Stop -ev err
}
}
Catch {
$Reader_Version.Remark = "Update Failed : " + $err.ErrorRecord.Exception.message
Return $Reader_Version
}
$PC_Reader_Version = Invoke-Command -Computer $ComputerName {
$INSTALLED = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate
$INSTALLED += Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate
$INSTALLED | ?{ $_.DisplayName -eq 'Adobe Acrobat Reader MUI' } | sort-object -Property DisplayName
} -ea Stop -ev err
$Reader_Version = $PC_Reader_Version | select @{N='ComputerName';E={$ComputerName}}, DisplayName, DisplayVersion, Publisher, InstallDate, @{N='Check_Date';E={$Cur_Date}}, @{N='IP';E={$DNS_IP}}, @{N='Remark';E={""}}
Return $Reader_Version
}
#####################
# Site Deploy #
#####################
$Sites = "TP"
New-PSDrive -name DOC -psprovider FileSystem -root "\\cifstp01\TP_Specific\IT\Networking\Reports\Adobe Reader"
$Date = (Get-Date).ToString("yyy.MM.dd_HH.m")
# Cleanup old pdf files - Change AddDays value as required
Get-ChildItem "DOC:\*.csv" | ? {$_.LastWriteTime -LT (Get-Date).AddDays(-7)} | Remove-Item -Confirm:$false
Foreach($Site in $Sites){
$PC_reader_Scan_Report = "DOC:\PC_reader_Scan_Report_$Date" + "_$Site.csv"
$PC_reader_Last_Scan_Report = "DOC:\PC_reader_Last_Scan_Report_$Site.csv"
$PC_reader_Last_Scan_list = Import-Csv $PC_reader_Last_Scan_Report | where {$_.DisplayVersion -eq $Web_Current_version}
$PC_reader_Up2date_list = $PC_reader_Last_Scan_list | where {$_.DisplayVersion -eq $Web_Current_version}
$PC_reader_Last_Scan_list | % {$Reader_Ver_HT=@{}} {$Reader_Ver_HT[$_.ComputerName] = $_.DisplayVersion}
$PC_reader_Last_Scan_list | % {$Reader_Install_Date_HT=@{}} {$Reader_Install_Date_HT[$_.ComputerName] = $_.InstallDate}
$ad_host_list = Get-ADComputer -LDAPFilter "(name=*pc*)" -SearchBase "ou=clients,ou=$Site,DC=ap,DC=vishayint,DC=com" | select name
$ad_computers = $ad_host_list.name
$computers = $ad_computers | where {$PC_Reader_Up2date_list.ComputerName -notcontains $_}
"$Site -- Will doing check computer count : $($computers.count)"
$Reader_Report = @()
$Reader_Report += $PC_Reader_Up2date_list
$Job_Count =0
Foreach($computer in $computers){
if ($Job_Count -ge 100) {
Get-Job | Wait-Job
$Jobs = Get-Job
Foreach($Job in $Jobs){
$output = Receive-job $Job.name
$Reader_Report += $output | select ComputerName, DisplayName, DisplayVersion, Publisher, InstallDate, Check_Date, IP, Remark
$Job_Count = 0
}
Get-Job | Remove-Job
}
$Reader_Ver = $Reader_Ver_HT[$computer]
$Reader_Install_Date = $Reader_Install_Date_HT[$computer]
Start-Job -ScriptBlock $Scriptblock -ArgumentList @($computer, $Web_Current_version, $Reader_Ver, $Reader_Install_Date) -Name $computer
$Job_Count += 1
}
Get-Job | Wait-Job
$Jobs = Get-Job
Foreach($Job in $Jobs){
$output = Receive-job $Job.name -keep
$Reader_Report += $output | select ComputerName, DisplayName, DisplayVersion, Publisher, InstallDate, Check_Date, IP, Remark
}
Get-Job | Remove-Job
$Reader_Report | Sort ComputerName | Export-Csv $PC_Reader_Scan_Report -NoTypeInformation -Encoding UTF8
$Reader_Report | Sort ComputerName | Export-Csv $PC_Reader_Last_Scan_Report -NoTypeInformation -Encoding UTF8
}
======================
If I run the content of scriptblock can be successfully installed on a single unit.
single deploy one PC script:
##################
Param (
$ComputerName ="pctp2032",
$Web_Current_version,
$Reader_Ver,
$Reader_Install_Date
)
$ErrorActionPreference = "Stop"
$Cur_Date = Get-Date
$Reader_Version = "" | Select-Object ComputerName, DisplayName, DisplayVersion, Publisher, InstallDate, Check_Date, IP, Remark
$Reader_Version.ComputerName = $ComputerName
$Reader_Version.DisplayName = "Adobe Acrobat Reader MUI"
$Reader_Version.DisplayVersion = $Reader_Ver
$Reader_Version.Publisher = "Adobe"
$Reader_Version.InstallDate = $Reader_Install_Date
$Reader_Version.Check_Date = $Cur_Date
Try {
$DNS_IP = (Get-ADComputer $ComputerName -Properties IPv4Address).IPv4Address
$Reader_Version.IP = $DNS_IP
}
Catch {
$Reader_Version.Remark = "Get-ADComputer IP Failed"
Return $Reader_Version
}
IF(-not (Test-Connection -ComputerName $ComputerName -Quiet -count 1)) {
$Reader_Version.Remark = "Offline"
Return $Reader_Version
}
Try {
$PC_IP = (Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName $ComputerName -ea Stop -ev err).ipaddress | Where-Object {$_ -like "10.2*"}
}
Catch {
$Reader_Version.Remark = "Check PC_IP Failed : " + $err.ErrorRecord.Exception.message
Return $Reader_Version
}
IF(-not ($ComputerName -eq ([System.Net.Dns]::GetHostByAddress($PC_IP).Hostname).Split('.')[0])) {
$Reader_Version.Remark = "DNS_IP don't mtch PC_IP"
Return $Reader_Version
}
Try {
$PC_Reader_Version = Invoke-Command -Computer $ComputerName {
$INSTALLED = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate
$INSTALLED += Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate
$INSTALLED | ?{ $_.DisplayName -eq 'Adobe Acrobat Reader MUI' } | sort-object -Property DisplayName -Unique
} -ea Stop -ev err
IF ($PC_Reader_Version.DisplayVersion -ne $Web_Current_version) {
$path = "\\$ComputerName\C$\temp"
If(!(test-path $path)) {
New-Item -ItemType Directory -Force -Path $path -ea Stop -ev err
}
Copy-Item -Path "D:\Iverson\PSScript\Reader\$SOFTNAME" -Destination "\\$ComputerName\c$\temp\$SOFTNAME" -Force -ea Stop -ev err
#$Result = Invoke-Command -computername $ComputerName -ScriptBlock {(Start-Process "msiexec" -ArgumentList "/p C:\temp\$SOFTNAME /quiet /norestart" -Wait -Passthru).ExitCode}
$Result = Invoke-Command -ComputerName $ComputerName -ScriptBlock {
param($tt)
(Start-Process msiexec "/p $tt /quiet /norestart" -Wait -PassThru).ExitCode
} -ArgumentList $tt
IF ($Result -ne 0) {
$Reader_Version.Remark = "Update Failed, returncode : " + $Result
Return $Reader_Version
}
else{
$Reader_Version.Remark = "Update Successfully"
Return $Reader_Version
}
Remove-item "\\$ComputerName\C$\temp\$SOFTNAME" -Force -ea Stop -ev err
}
}
Catch {
$Reader_Version.Remark = "Update Failed : " + $err.ErrorRecord.Exception.message
Return $Reader_Version
}
$PC_Reader_Version = Invoke-Command -Computer $ComputerName {
$INSTALLED = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate
$INSTALLED += Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate
$INSTALLED | ?{ $_.DisplayName -eq 'Adobe Acrobat Reader MUI' } | sort-object -Property DisplayName
} -ea Stop -ev err
$Reader_Version = $PC_Reader_Version | select @{N='ComputerName';E={$ComputerName}}, DisplayName, DisplayVersion, Publisher, InstallDate, @{N='Check_Date';E={$Cur_Date}}, @{N='IP';E={$DNS_IP}}, @{N='Remark';E={""}}
Return $Reader_Version
########################
Why I used scriptblock include our deploy script get fail by exitcode:87.
The content of the scriptblock can be successfully installed on a single computer, but error code 87 is obtained when multiple computers are installed and executed.
2023-03-21_8-59-47.jpg
2023-03-21_9-00-21.jpg