Functions/Public/Start-WindowsUpdate.ps1
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 |
function Start-WindowsUpdate { # Windows Update by using the module PSWindowsUpdate $moduleName = "PSWindowsUpdate" if (Get-Module -ListAvailable -Name $moduleName) { Import-Module $moduleName Write-Output "Module $moduleName exists." $currentDate = Get-Date -Format "yyyy-MM-dd" $desktopPath = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::Desktop) $outputFilePath = "$desktopPath\$currentDate-WindowsUpdate_Patches_Installed.txt" Write-Output "Installing Windows Updates... Please be patient!" Install-WindowsUpdate -MicrosoftUpdate -UpdateType Software -AcceptAll | Out-File $outputFilePath -force Write-Output "All patches have been installed. Thanks for your patience." } else { Write-Output "Module $moduleName does not exist." try { Install-Module -Name $moduleName -Force Write-Output "Module $moduleName has been installed." } catch { Write-Error $_.ErrorDetails } } } |