Invoke-Command -answer the question of installing updates and restarting
i have script makes updates of operating system
script possible answer question of whether install updates , whether restart server end
answer automatically ran following command:
c: \ wsus.ps1 y y
want use command
invoke-command -computername (get-content c: \ scripts \ servers.txt) -filepath c: \ wsus.ps1
how answer question of installing updates , restarting
thank you
# script: wsus.ps1 # author: gregory strike # website: www.gregorystrike.com # date: 02-19-2010 # information: script adapated wua_searchdownloadinstall.vbs vbscript microsoft. uses # microsoft.update.session com object query wsus server, find applicable updates, , install them. # # wsus.ps1 little less verbose doing when compared orginal vbscript. # lines exist in code below show same information original commented out. # # # wsus.ps1 can automatically install applicable updates passing y script. default # behavior ask whether or not install new updates. # # syntax: .\wsus.ps1 [install] [reboot] # [install] optional , can "y", "yes", "no" or "n" # whether or not install updates automatically. if null, user prompted. # # [reboot] optional , can "y", "yes", "no" or "n", # if updates require reboot, whether or not reboot automatically. if null, user # prompted. $updatesession = new-object -com microsoft.update.session $updatesearcher = $updatesession.createupdatesearcher() write-host("searching applicable updates...") -fore green $searchresult = $updatesearcher.search("isinstalled=0 , type='software'") write-host("") write-host("list of applicable items on machine:") -fore green ($x = 0; $x -lt $searchresult.updates.count; $x++){ $update = $searchresult.updates.item($x) write-host( ($x + 1).tostring() + "> " + $update.title) } if ($searchresult.updates.count -eq 0) { write-host("there no applicable updates.") exit } #write-host("") #write-host("creating collection of updates download:") -fore green $updatestodownload = new-object -com microsoft.update.updatecoll ($x = 0; $x -lt $searchresult.updates.count; $x++){ $update = $searchresult.updates.item($x) #write-host( ($x + 1).tostring() + "> adding: " + $update.title) $null = $updatestodownload.add($update) } write-host("") write-host("downloading updates...") -fore green $downloader = $updatesession.createupdatedownloader() $downloader.updates = $updatestodownload $null = $downloader.download() #write-host("") #write-host("list of downloaded updates...") -fore green $updatestoinstall = new-object -com microsoft.update.updatecoll ($x = 0; $x -lt $searchresult.updates.count; $x++){ $update = $searchresult.updates.item($x) if ($update.isdownloaded) { #write-host( ($x + 1).tostring() + "> " + $update.title) $null = $updatestoinstall.add($update) } } $install = [system.string]$args[0] $reboot = [system.string]$args[1] if (!$install){ $install = read-host("would install these updates now? (y/n)") } if ($install.toupper() -eq "y" -or $install.toupper() -eq "yes"){ write-host("") write-host("installing updates...") -fore green $installer = $updatesession.createupdateinstaller() $installer.updates = $updatestoinstall $installationresult = $installer.install() write-host("") write-host("list of updates installed results:") -fore green ($x = 0; $x -lt $updatestoinstall.count; $x++){ write-host($updatestoinstall.item($x).title + ": " + $installationresult.getupdateresult($x).resultcode) } write-host("") write-host("installation result: " + $installationresult.resultcode) write-host(" reboot required: " + $installationresult.rebootrequired) if ($installationresult.rebootrequire -eq $true){ if (!$reboot){ $reboot = read-host("would install these updates now? (y/n)") } if ($reboot.toupper() -eq "y" -or $reboot.toupper() -eq "yes"){ write-host("") write-host("rebooting...") -fore green (get-wmiobject -class win32_operatingsystem).reboot() } } } אם תגובתי פתרה את בעייתך - לחץ/י, על "סמן כתשובה" ליד סימן ה v הירוק.
to pass arguments invoke-command this:
invoke-command -computername (get-content c: \ scripts \ servers.txt) -filepath c: \ wsus.ps1 -argumentlist "y y"
\_(ツ)_/
Windows Server > Windows PowerShell
Comments
Post a Comment