Windows update 2

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

Windows update 2

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

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

#write-host $ComputerName
## Define files with Computer information
$fullPathIncFileName = $MyInvocation.MyCommand.Definition
$currentScriptName = $MyInvocation.MyCommand.Name
$currentExecutingPath = $fullPathIncFileName.Replace($currentScriptName, "")
$csvSource=$currentScriptName.trimend("ps1")+"csv"
$csvSav=$currentScriptName.trimend("ps1")+"-sav.csv"
$csvDest=$currentScriptName.trimend("ps1")+"-Out.csv"
$LogFile = $currentScriptName.trimend("ps1")+"log"
$reports = @()
$Delimiter="`t"
#write-host $LogFile

$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 {
#Get Date
$DateAndTime = (Get-Date -format ddMMMyyyy-HH.mm)
$Criteria = "IsInstalled=0 and Type='Software'"
$Criteria = "IsAssigned=1 and IsHidden=0 and IsInstalled=0"
$Criteria = "IsInstalled=0"

$updateSession = new-object -com "Microsoft.Update.Session"

write-progress -Activity "Updating" -Status "Checking available updates"
$updates=$updateSession.CreateupdateSearcher().Search($criteria).Updates
write-host "Total of updates to install: " $Updates.Count

$CountFix=Get-HotFix
write-host "Total of updates installed : " $CountFix.Count


}

Remove-PSSession -Session $Session

Return to “PowerShell”

Who is online

Users browsing this forum: No registered users and 1 guest