Windows update 4

User avatar
daniel
Site Admin
Posts: 223
Joined: Tue Jan 09, 2007 9:54 pm
Contact:

Windows update 4

Postby daniel » Wed May 15, 2019 12:42 pm

# This Script is for removing Tasks secheduled : Remove_Deployment_Team & InstallUpdates
# Path : \Microsoft\Windows\PowerShell\ScheduledJobs\
# It can be executed remotely :
# .\Unreg_Deploy_Updates_Task.ps1 ServerName

[cmdletbinding()]
param (
[string]$ComputerName = $env:computername
)

write-host $ComputerName

$Session = Get-PSSession | where { $_.ComputerName -eq $ComputerName -and $_.State -eq 'Opened' }
if (-not $Session) {
try { $Session = New-PSSession -ComputerName $ComputerName -EA 1 } catch { throw }
}




Invoke-Command -Session $Session -ScriptBlock {

Write-Host "Get Schedule Task Windows Update ....."
$Count = 0
while ((Get-ScheduledTask -TaskPath "\Microsoft\Windows\PowerShell\ScheduledJobs\" | Where-Object {($_.TaskName -like "InstallUpdates*") -and ($_.State -like "Running")}))
{

$updateSession = new-object -com "Microsoft.Update.Session"
$updates=$updateSession.CreateupdateSearcher().Search($criteria).Updates
write-host "Total of updates to install: " $Updates.Count

$PendingFile = $false
$AutoUpdate = $false

#Determine PendingFileRenameOperations exists of not
#$PendFileKeyPath = "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\"
#Get-ItemProperty -Path $PendFileKeyPath -name PendingFileRenameOperations -ErrorAction SilentlyContinue | Foreach{If($_.PendingFileRenameOperations){$PendingFile = $true}Else{$PendingFile = $false}}

#Determine RebootRequired subkey exists or not
#$AutoUpdateKeyPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update"
#Test-Path -Path "AutoUpdateKeyPath\RebootRequired" | Foreach{If($_ -eq $true){$AutoUpdate = $true}Else{$AutoUpdate = $false}}

If($PendingFile -or $AutoUpdate )
{
# write-host "reboot required "
}
Else
{
# write-host "reboot not required "

}
Start-Sleep 10
}

Write-Host "Schedule Task Windows Update completed."


} #End Invoke Scriptlock


Remove-PSSession -Session $Session

Return to “PowerShell”

Who is online

Users browsing this forum: No registered users and 1 guest