1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
| param (
[bool]$analyse = 1,
[bool]$update = 0,
[bool]$silent = 1
)
Start-Transcript -Path "C:\hpia\logs\hpia-script.log" -Force
function Write-Log {
param (
[string]$Message,
[string]$LogFile = "C:\HPIA\Logs\HPIA_analyze.log",
[string]$LogLevel = "INFO"
)
# Ensure the log directory exists
$logDir = [System.IO.Path]::GetDirectoryName($LogFile)
if (-not (Test-Path -Path $logDir)) {
New-Item -ItemType Directory -Path $logDir -Force
}
# Create a timestamp
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
# Format the log message
$logMessage = "$timestamp [$LogLevel] - $Message"
# Write the log message to the log file
Add-Content -Path $LogFile -Value $logMessage
}
$logpath = "C:\HPIA\Logs\" #Oder Netzwerkpfad
if (Test-Path -Path D:\) {
$downloadfolder = "D:\MEINPFAD\Treiber"
} else {
$downloadfolder = "C:\HPIA\Downloads\"
}
if (Test-Path -Path 'C:\HPIA\HP Image Assistant\HPImageAssistant.exe') {
$assistantfilepath = 'C:\HPIA\HP Image Assistant\HPImageAssistant.exe'
$assistantversion = "5.3.0.506"
$currentversion = (Get-Command $assistantfilepath).FileVersionInfo.FileVersion
if ($currentversion -lt $assistantversion) {
if (Test-Path -Path "NETWORKPATH\HP\hp-hpia-5.3.0.exe") {
Start-Process "NETWORKPATH\HP\hp-hpia-5.3.0.exe" -ArgumentList "/s /e /f `"C:\HPIA\HP Image Assistant`"" -wait
}
}
} else {
if (Test-Path -Path "NETWORKPATH\HP\hp-hpia-5.3.0.exe") {
Start-Process "NETWORKPATH\HP\hp-hpia-5.3.0.exe" -ArgumentList "/s /e /f `"C:\HPIA\HP Image Assistant`"" -wait
}
}
if (-not (Test-Path -Path $logpath)) {
try {
$reportfolder = new-item -Path "$($logpath)" -ItemType Directory -ErrorAction Continue
} catch { Write-Host "Error." }
}
if ($analyse -eq $true) {
$args = @(
"/Operation:Analyze",
"/Silent",
"/AutoCleanup",
"/Action:List",
"/reportfolder:$($logpath)"
)
Start-Process "C:\HPIA\HP Image Assistant\HPImageAssistant.exe" -argumentlist $args -wait
}
if ($update -eq $true) {
if ($silent -eq $true) {
$args = @(
"/Auto",
"/Category:All",
"/selection:all",
"/AutoCleanup",
"/Silent",
"/reportfolder:$($logpath)",
"/SoftpaqDownloadFolder:$($downloadfolder)"
)
} else {
$args = @(
"/Auto",
"/Category:All",
"/selection:all",
"/AutoCleanup",
"/Noninteractive",
"/reportfolder:$($logpath)",
"/SoftpaqDownloadFolder:$($downloadfolder)"
)
}
try {
$updateresult = Start-Process "C:\HPIA\HP Image Assistant\HPImageAssistant.exe" -argumentlist $args -wait
write-log -message "$($updateresult)" -errorcode "INFO"
} catch {
$errorcode = $_
Write-Log -Message "$($errorcode)" -errorcode "ERROR" -LogFile "$($logpath)\HPIA-analyze.log"
}
# Energiespareinstellungen normalisieren
#Aktiviert wieder das Ausbalancierte Schema
powercfg /SETDCVALUEINDEX SCHEME_CURRENT 2a737441-1930-4402-8d77-b2bebba308a3 48e6b7a6-50f5-4782-a5d4-53bb8f07e226 0 # Selective USB Energiesparen Batteriebetrieben
powercfg /SETACVALUEINDEX SCHEME_CURRENT 2a737441-1930-4402-8d77-b2bebba308a3 48e6b7a6-50f5-4782-a5d4-53bb8f07e226 0 # Selective USB Energiesparen am Ladegerät
powercfg /change monitor-timeout-ac 0
powercfg /change monitor-timeout-dc 20
powercfg /change standby-timeout-dc 60
powercfg /change standby-timeout-ac 0
powercfg /S SCHEME_CURRENT
powercfg /h off
$latest = get-childitem -path C:\hpia\logs | Where-Object {$_.Name -Like "*Readme*"} | Sort-Object LastAccessTime -Descending | Select-Object -First 1
$mailadmin = "adminmail@bla.de"
$mailfrom = "noreply@bla.de"
$mailserver = "smtp.server.de"
$mailsubject = "HP Image Assistant Log for $($env:computername)"
$mailbody = "See HP Image Assistant Log attached to this email."
try {
Send-MailMessage -BodyAsHtml -body $mailbody -To $mailadmin -From $mailfrom -Encoding UTF8 -SmtpServer $mailserver -Subject $mailsubject -Attachments "$($latest.FullName)"
} catch {
$errorcode = $_
write-host "ERROR: $errorcode"
}
}
Stop-Transcript
|