I would like to use the standard script for windows that is in pulseway automation.
But I get this error message:
Checking for Windows updates
Downloading updates
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
At C:\Program Files\Pulseway\automation_9fdca742_c373_41fb_80e3_ce2b245530ca.ps1:25 char:5
+ $Downloader = $Session.CreateUpdateDownloader()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], UnauthorizedAccessException
+ FullyQualifiedErrorId : System.UnauthorizedAccessException
The user used to execute the script (Settings - runtime) is a domain admin.
The script works if I execute powershell as an administrator.
In pulseway, with automation I cannot state that the script must be executed as admin.
Am I missing something?
Thanks in advance!
Printscreens in attachement
Script:
Write-Host "Checking for Windows updates"
$UpdateCollection = New-Object -ComObject Microsoft.Update.UpdateColl
$Searcher = New-Object -ComObject Microsoft.Update.Searcher
$Session = New-Object -ComObject Microsoft.Update.Session
$Searcher = New-Object -ComObject Microsoft.Update.Searcher
$results = $searcher.search("Type='software' AND IsInstalled = 0 AND IsHidden = 0 AND AutoSelectOnWebSites = 1")
# install update items
Write-Host "Installing updates"
$Installer = New-Object -ComObject Microsoft.Update.Installer
$Installer.Updates = $UpdateCollection
$InstallationResult = $Installer.Install()
# Check Result
if ($InstallationResult.ResultCode -eq 2){
Write-Host "Updates installed successfully"
} else {
Write-Host "Some updates could not be installed"
}
if ($InstallationResult.RebootRequired){
Write-Host "System needs to reboot"
# uncomment the following line to automatically reboot the system if a reboot is required after the updates are installed
#shutdown -r -f -t 300 -c "Rebooting in 5 minutes to apply Windows updates"
}
}
Good evening,
I would like to use the standard script for windows that is in pulseway automation.
But I get this error message:
Checking for Windows updates
Downloading updates
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
At C:\Program Files\Pulseway\automation_9fdca742_c373_41fb_80e3_ce2b245530ca.ps1:25 char:5
+ $Downloader = $Session.CreateUpdateDownloader()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], UnauthorizedAccessException
+ FullyQualifiedErrorId : System.UnauthorizedAccessException
The user used to execute the script (Settings - runtime) is a domain admin.
The script works if I execute powershell as an administrator.
In pulseway, with automation I cannot state that the script must be executed as admin.
Am I missing something?
Thanks in advance!
Printscreens in attachement
Script:
Write-Host "Checking for Windows updates"
$UpdateCollection = New-Object -ComObject Microsoft.Update.UpdateColl
$Searcher = New-Object -ComObject Microsoft.Update.Searcher
$Session = New-Object -ComObject Microsoft.Update.Session
$Searcher = New-Object -ComObject Microsoft.Update.Searcher
$results = $searcher.search("Type='software' AND IsInstalled = 0 AND IsHidden = 0 AND AutoSelectOnWebSites = 1")
#Install WindowsUpdate Module
Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted
Install-Module PSWindowsUpdate
# Install Update
if ($results.Updates.Count -eq 0) {
Write-Host "No updates found"
# no updates.
} else {
# setup update collection
foreach ($update in $results.Updates){
$UpdateCollection.Add($update) | out-null
}
# download update items
Write-Host "Downloading updates"
$Downloader = $Session.CreateUpdateDownloader()
$Downloader.Updates = $UpdateCollection
$Downloader.Download()
# install update items
Write-Host "Installing updates"
$Installer = New-Object -ComObject Microsoft.Update.Installer
$Installer.Updates = $UpdateCollection
$InstallationResult = $Installer.Install()
# Check Result
if ($InstallationResult.ResultCode -eq 2){
Write-Host "Updates installed successfully"
} else {
Write-Host "Some updates could not be installed"
}
if ($InstallationResult.RebootRequired){
Write-Host "System needs to reboot"
# uncomment the following line to automatically reboot the system if a reboot is required after the updates are installed
#shutdown -r -f -t 300 -c "Rebooting in 5 minutes to apply Windows updates"
}
}
Edited by Chris1992