{"id":276,"date":"2017-05-01T23:07:42","date_gmt":"2017-05-01T14:07:42","guid":{"rendered":"http:\/\/shinke1987.net\/?p=276"},"modified":"2017-05-24T12:53:19","modified_gmt":"2017-05-24T03:53:19","slug":"post-276","status":"publish","type":"post","link":"https:\/\/shinke1987.net\/?p=276","title":{"rendered":"WPS\u3067WindowsUpdate\u306e\u518d\u8d77\u52d5\u307e\u3067\u3092\u81ea\u52d5\u5316\u3002"},"content":{"rendered":"<h2>\u74b0\u5883<\/h2>\n<p>Windows 7 Professional 64bit<br \/>\nWPS\uff1aVer2.0<\/p>\n<p>&nbsp;<\/p>\n<h2>\u76ee\u6a19<\/h2>\n<p>1\u5ea6\u5b9f\u884c\u3057\u305f\u3089\u518d\u8d77\u52d5\u307e\u3067\u3084\u3063\u3066\u304f\u308c\u308b\u3002<\/p>\n<p>\u30c9\u30e9\u30a4\u30d0\u4ee5\u5916\u306e\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3092\u5168\u3066\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u6b21\u306e\u76ee\u6a19<\/h2>\n<p>OS\u3092\u518d\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u304b\u3089\u3001<\/p>\n<p>1\u5ea6\u5b9f\u884c\u3057\u305f\u3089\u8907\u6570\u56de\u4ee5\u4e0a\u306e\u518d\u8d77\u52d5\u3082\u542b\u3081\u3066\u3001<\/p>\n<p>\u5168\u3066\u306eWindowsUpdate\u306e\u51e6\u7406\u3092\u7d42\u308f\u3089\u305b\u3066\u304f\u308c\u308b\u30b9\u30af\u30ea\u30d7\u30c8\u306b\u3057\u305f\u3044\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u8ffd\u8a18\uff082017\u5e745\u67082\u65e5\uff09<\/h2>\n<p>91\u884c\u76ee\u306e\u3001<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">$Installer = $Session.CreateUpdateInstaller()<\/pre>\n<p>\u306f\u3001\u30ea\u30e2\u30fc\u30c8\u304b\u3089\u306f\u3067\u304d\u306a\u3044\u3089\u3057\u3044\u3002<br \/>\n\u53c2\u8003\u2192<a href=\"https:\/\/technet.microsoft.com\/ja-jp\/library\/security\/aa386863.aspx\">https:\/\/technet.microsoft.com\/ja-jp\/library\/security\/aa386863.aspx<\/a><\/p>\n<p>\u3082\u3057\u3084\u308b\u3068\u3001\u3053\u3093\u306a\u30a8\u30e9\u30fc\u304c\u51fa\u308b\u3002<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">&quot;0&quot; \u500b\u306e\u5f15\u6570\u3092\u6307\u5b9a\u3057\u3066 &quot;CreateUpdateInstaller&quot; \u3092\u547c\u3073\u51fa\u3057\u4e2d\u306b\u4f8b\u5916\u304c\u767a\u751f\u3057\u307e\u3057\u305f: &quot;\u30a2\u30af\u30bb\u30b9\u304c\u62d2\u5426\u3055\u308c\u307e\u3057\u305f\u3002 (HRESULT \u304b\u3089\u306e\u4f8b\u5916: 0x80070005 (E_ACCESSDENIED))&quot;<\/pre>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">$Installer = New-Object -ComObject Microsoft.Update.Installer<\/pre>\n<p>\u3068\u3084\u308b\u3068\u89e3\u6c7a\u3067\u304d\u308b\u304b\u3082\u3057\u308c\u306a\u3044\u3002<br \/>\n\u6642\u9593\u3067\u304d\u305f\u3089\u8a66\u3059\u3002<br \/>\n\u3010\u5e73\u621029\u5e745\u67089\u65e5(\u706b)\u8ffd\u8a18\u3011<br \/>\n\u30c0\u30e1\u3060\u3063\u305f\u3002\u305d\u3082\u305d\u3082Windows\u304c\u30ea\u30e2\u30fc\u30c8\u3067\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3067\u304d\u306a\u3044\u3088\u3046\u306b\u3057\u3066\u308b\u307f\u305f\u3044\u3002<br \/>\n\u3082\u3046\u30bf\u30b9\u30af\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u4f7f\u3046\u3057\u304b\u306a\u3044\u3002<br \/>\n\u30bf\u30b9\u30af\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u3067\u6df1\u591c\u306b\u5b9f\u884c\u3059\u308b\u3088\u3046\u306b\u8a2d\u5b9a\u3057\u3066\u3001<br \/>\n\u305d\u306e\u6642\u9593\u306e\u3061\u3087\u3044\u524d\u306bWOL\u3068\u304b\u3067\u8d77\u52d5\u3059\u308b\u3088\u3046\u306b\u3059\u308b\u3057\u304b\u306a\u3044\u304b\u3082\u3002<\/p>\n<p><a href=\"https:\/\/shinke1987.net\/?p=296\">WPS\u304b\u3089\u30bf\u30b9\u30af\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u3092\u5229\u7528\u3059\u308b\u3002<\/a><br \/>\n\u3092\u53c2\u8003\u306b\u3057\u305f\u3089\u3067\u304d\u308b\u306f\u305a\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u30b3\u30fc\u30c9<\/h2>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n$yyyymmdd = Get-Date -uformat &quot;%Y%m%d&quot;\r\n$NumOfUpdates = 0\r\n$IsThereUpdates = &quot;&quot;\r\n$IsThereInstall = &quot;&quot;\r\n$UpdateTitles = @()\r\n$InstallTitles = @()\r\n$CheckDownload = 0\r\n$FlagDownload = 0\r\n$FlagInstall = 0\r\n$LogResult = &quot;&quot;\r\n$NeedReboot = &quot;\u518d\u8d77\u52d5\u306f\u4e0d\u8981\u3067\u3059\u3002&quot;\r\n\r\n$Today = Get-Date\r\n\r\n$Session = New-Object -ComObject Microsoft.Update.Session\r\n$Searcher = $Session.CreateUpdateSearcher()\r\n\r\nWrite-Host &quot;\u521d\u671f\u5316\u4e2d\u3002\u3002\u3002`r`n&quot; -ForegroundColor &quot;Yellow&quot;\r\n# $Results = $Searcher.Search(&quot;IsInstalled = 0 AND Type = 'Software' And AutoSelectOnWebSites = 1&quot;)\r\n$Results = $Searcher.Search(&quot;IsInstalled = 0 AND Type != 'Driver'&quot;)\r\n$NumOfUpdates = $Results.Updates.Count\r\n\r\n# \u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u304c\u3042\u308b\u304b\u3092\u78ba\u8a8d\u3002\r\nif ($NumOfUpdates -eq 0) {\r\n    $IsThereUpdates = &quot;\u5229\u7528\u53ef\u80fd\u306a\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u306f\u3042\u308a\u307e\u305b\u3093\u3002`r`n&quot;\r\n    Write-Host &quot;$IsThereUpdates&quot;\r\n}\r\nelse {\r\n    $IsThereUpdates = &quot;\u5229\u7528\u53ef\u80fd\u306a\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u304c\u3042\u308a\u307e\u3059\uff1a&quot; + $NumOfUpdates + &quot; \u4ef6`r`n&quot;\r\n    Write-Host &quot;$IsThereUpdates&quot;\r\n    # \u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u306e\u5185\u5bb9\u3092\u8868\u793a\u3002\r\n    foreach ($Result in $Results.Updates) {\r\n        $UpdateTitles += $Result.Title\r\n        Write-Host &quot;\u30fb&quot; $Result.Title\r\n    }\r\n    $CheckDownload = 1\r\n}\r\n\r\n# \u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u3082\u306e\u304c\u3042\u308b\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3002\r\nif ($CheckDownload -eq 1) {\r\n    foreach ($Update in $Results.Updates) {\r\n        if ($Update.IsDownloaded) {\r\n            Write-Host &quot;\u904e\u53bb\u306b\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u6e08\u307f\uff1a&quot; $Update.Title\r\n            $FlagInstall = 1\r\n        }\r\n        else {\r\n            $FlagDownload = 1\r\n            Write-Host &quot;\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u4e88\u5b9a\uff1a&quot; $Update.Title\r\n        }\r\n    }\r\n}\r\nWrite-Host \r\n\r\n# \u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3092\u884c\u3046\u3002\r\n$DLColl = New-Object -ComObject Microsoft.Update.UpdateColl\r\nif ($Flagdownload -eq 1) {\r\n    foreach ($Update in $Results.Updates) {\r\n        $DLColl.Add($Update) | Out-Null\r\n    }\r\n    $Downloader = $Session.CreateUpdateDownloader()\r\n    $Downloader.Updates = $DLColl\r\n    $Downloader.Download()\r\n    # \u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u5f8c\u306e\u78ba\u8a8d\u3002\r\n    foreach ($Update in $Results.Updates) {\r\n        if ($Update.IsDownloaded) {\r\n            Write-Host &quot;\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u5b8c\u4e86\uff1a&quot; $Update.Title\r\n            $FlagInstall = 1\r\n        }\r\n        else {\r\n            Write-Host &quot;\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u5931\u6557\uff1a&quot; $Update.Title\r\n        }\r\n    }\r\n}\r\nWrite-Host \r\n\r\n# \u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3092\u884c\u3046\u3002\r\n$InstallColl = New-Object -ComObject Microsoft.Update.UpdateColl\r\nforeach ($Update in $Results.Updates) {\r\n    if ($Update.IsDownloaded) {\r\n        $InstallColl.Add($Update) | Out-Null\r\n        $InstallTitles += $Update.Title\r\n    }\r\n}\r\nif ($InstallColl.Count -eq 0) {\r\n    $IsThereInstall = &quot;\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3067\u304d\u308b\u66f4\u65b0\u30d5\u30a1\u30a4\u30eb\u304c\u3042\u308a\u307e\u305b\u3093\u3002&quot;\r\n    Write-Host $IsThereInstall\r\n}\r\nelse {\r\n    $IsThereInstall = &quot;\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u4e88\u5b9a\u306e\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\uff1a&quot; + $InstallColl.Count + &quot; \u4ef6&quot;\r\n    Write-Host &quot;\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3092\u958b\u59cb\u3057\u307e\u3057\u305f\u3002( &quot; $InstallColl.Count &quot; \u4ef6)&quot;\r\n    $Installer = $Session.CreateUpdateInstaller()\r\n    $Installer.Updates = $InstallColl\r\n    $InstallResult = $Installer.Install()\r\n    if ($InstallResult.ResultCode -eq 2) {\r\n        $LogResult = &quot;\u5168\u3066\u306e\u66f4\u65b0\u30d5\u30a1\u30a4\u30eb\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3057\u305f\u3002&quot;\r\n        Write-Host $LogResult\r\n    }\r\n    if ($InstallResult.ResultCode -eq 3) {\r\n        $LogResult = &quot;\u30a8\u30e9\u30fc\u306f\u767a\u751f\u3057\u307e\u3057\u305f\u304c\u3001\u5b8c\u4e86\u3057\u307e\u3057\u305f\u3002&quot;\r\n        Write-Host $LogResult\r\n    }\r\n    if ($InstallResult.ResultCode -eq 4) {\r\n        $LogResult = &quot;\u5931\u6557\u3057\u307e\u3057\u305f\u3002&quot;\r\n        Write-Host $LogResult\r\n    }\r\n    if ($InstallResult.ResultCode -eq 5) {\r\n        $LogResult = &quot;\u51e6\u7406\u304c\u30ad\u30e3\u30f3\u30bb\u30eb\u3055\u308c\u307e\u3057\u305f\u3002&quot;\r\n        Write-Host $LogResult\r\n    }\r\n}\r\n\r\n# \u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u751f\u6210\u3002\r\n$LogFile = $yyyymmdd + $Env:ComputerName + &quot;.log&quot;\r\n&quot;Windows Power Shell Script\u3067\u81ea\u52d5\u751f\u6210\u3055\u308c\u305f\u30ed\u30b0\u3067\u3059\u3002&quot; &gt; $LogFile\r\n&quot;\u751f\u6210\u3057\u305f\u30d5\u30a1\u30a4\u30eb\uff1aAutoWU.ps1&quot; &gt;&gt; $LogFile\r\n&quot;\u751f\u6210\u3057\u305f\u5e74\u6708\u65e5\uff1a$Today`r`n&quot; &gt;&gt; $LogFile\r\n&quot;=======================================================================`r`n&quot; &gt;&gt; $LogFile\r\n$IsThereUpdates &gt;&gt; $LogFile\r\nfor ($i = 0; $i -lt $NumOfUpdates; $i++) {\r\n    &quot;\u3010 &quot; + ($i + 1) + &quot; \u3011&quot; + $UpdateTitles&#x5B;$i] &gt;&gt; $LogFile\r\n}\r\n$IsThereInstall &gt;&gt; $LogFile\r\nfor ($i = 0; $i -lt $InstallColl.Count; $i++) {\r\n    &quot;\u3010 &quot; + ($i + 1) + &quot; \u3011&quot; + $InstallTitles&#x5B;$i] &gt;&gt; $LogFile\r\n}\r\nWrite-Host \r\n&quot;=======================================================================`r`n&quot; &gt;&gt; $LogFile\r\n$LogResult &gt;&gt; $LogFile\r\n$Today = Get-Date\r\n&quot;\u5b8c\u4e86\u6642\u523b\uff1a$Today&quot; &gt;&gt; $LogFile\r\n\r\n\r\n# \u518d\u8d77\u52d5\u304c\u5fc5\u8981\u304b\u3069\u3046\u304b\u3092\u78ba\u8a8d\u3059\u308b\u3002\r\nif ($InstallResult.RebootRequired) {\r\n    $NeedReboot = &quot;\u518d\u8d77\u52d5\u304c\u5fc5\u8981\u3067\u3059\u3002`r`n10\u79d2\u5f8c\u306b\u518d\u8d77\u52d5\u3057\u307e\u3059\u3002&quot;\r\n    $NeedReboot &gt;&gt; $LogFile\r\n    Write-Host &quot;\u518d\u8d77\u52d5\u304c\u5fc5\u8981\u3067\u3059\u3002&quot;\r\n    Write-Host &quot;10\u79d2\u5f8c\u306b\u518d\u8d77\u52d5\u3057\u307e\u3059\u3002&quot;\r\n    Start-Sleep -s 10\r\n    shutdown \/r \/t 0\r\n}\r\nelse {\r\n    $NeedReboot &gt;&gt; $LogFile\r\n}\r\n\r\n# \u5b8c\u4e86\u3002\r\nWrite-Host &quot;Windows Update \u306f\u5b8c\u4e86\u3057\u307e\u3057\u305f\u3002&quot;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u74b0\u5883 Windows 7 Professional 64bit WPS\uff1aVer2.0 &nbsp; \u76ee\u6a19 1\u5ea6\u5b9f\u884c\u3057\u305f\u3089\u518d\u8d77\u52d5\u307e\u3067\u3084\u3063\u3066\u304f\u308c\u308b\u3002 \u30c9\u30e9\u30a4\u30d0\u4ee5\u5916\u306e\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3092\u5168\u3066\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3002 &nbsp; \u6b21\u306e\u76ee\u6a19 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[17,44],"class_list":["post-276","post","type-post","status-publish","format-standard","hentry","category-windowspowershell","tag-windows","tag-windowspowershell"],"_links":{"self":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts\/276","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=276"}],"version-history":[{"count":10,"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts\/276\/revisions"}],"predecessor-version":[{"id":322,"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts\/276\/revisions\/322"}],"wp:attachment":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=276"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=276"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=276"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}