Quantcast
Channel: shirokichi's hobby life
Viewing all articles
Browse latest Browse all 215

【メモ】PSWindowsUpdate -コマンドラインでWindows Update- (Windows Server 2012 R2 Essentials)

$
0
0
コマンドラインからのWindows Updateは山市氏が紹介されているvbsを使ってきた。
Windows Scripting: Windows Update をスクリプトから ( WindowsUpdate.vbs ) 2010/07の記事
Windows Scripting: Windows Update をリモートから ( PowerShell Remoting は NG ) 2010/07の記事
このスクリプトWin7時代は大変重宝したのだけれど、Win8/Win8.1/Win2012(R2)では相性がよろしくないようで、更新を取りこぼすことがあった。
これにかわるものとして、PSWindowsUpdateというものを見つけたので導入してみたメモ。

cmd.exeとPowerShell.exe上でのクリップボードペーストはAlt + Space → E → P
(正確にクリップボードバッファを捉えないときもあり。)

確認事項:実行ポリシー

PS C:\> Get-ExecutionPolicy
RemoteSigned
(初期値Restricted、詳しい解説はここ)

Step1:Chocolateyのインストール
PSでなく、cmd.exeから
C:\> @powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%systemdrive%\chocolatey\bin

Step2:Windows Update PowerShell Moduleのインストール
PS、cmd.exeどちらでも
C:\> cinst PSWindowsUpdate 
ここで一旦ログアウトし、パスを反映さたほうがいいかもしれない。

Step3: $env:PSModulePath でモジュールのパスを確認
C:\> $env:PSModulePath
C:\Users\Administrator\Documents\WindowsPowerShell\Modules;C:\Program Files (x86)\WindowsPowerShell\Modules;C:\Windows\
system32\WindowsPowerShell\v1.0\Modules\
C:\Users\Administrator\Documents\WindowsPowerShell\Modules にインストールされたPSWindowsUpdate を
C:\windows\system32\WindowsPowerShell\v1.0\Modules
にコピー

(~\Documents\WindowsPowerShell\Module に置けばOKという解説がありますが、Windows Server 2012 R2 ではシステムディレクトリに置かないと動作しませんでした。)

インストール先がどこか分からなくなった場合は、エクスプローラ等で PSWindowsUpdate を検索かけてみる。

パスが通っていないかもしれないので、ここで一旦ログアウト(サインアウト)するとよいかもしれない。

Step4: モジュールのImport
C:\> Import-Module PSWindowsupdate

Step5: 動作確認
C:\> Get-Command -Module PSWindowsupdate

CommandType     Name                                               ModuleName
-----------     ----                                               ----------
Function        Add-WUOfflineSync                                  pswindowsupdate
Function        Add-WUServiceManager                               pswindowsupdate
Function        Get-WUHistory                                      pswindowsupdate
Function        Get-WUInstall                                      pswindowsupdate
Function        Get-WUInstallerStatus                              pswindowsupdate
Function        Get-WUList                                         pswindowsupdate
Function        Get-WURebootStatus                                 pswindowsupdate
Function        Get-WUServiceManager                               pswindowsupdate
Function        Get-WUUninstall                                    pswindowsupdate
Function        Hide-WUUpdate                                      pswindowsupdate
Function        Invoke-WUInstall                                   pswindowsupdate
Function        Remove-WUOfflineSync                               pswindowsupdate
Function        Remove-WUServiceManager                            pswindowsupdate
Function        Update-WUModule                                    pswindowsupdate


Step6: 完了、Windows Updateを試す
C:\> Get-WUList
-------------------
C:\> Get-WUInstall
-------------------

参考:
PowerShellをMicrosoft Updateに対応させ,historyをセッションを超えて保存できるようにする
(直立二速歩行
【Management】Windows Update Powershell Module (1)
(フィールドSEあがりの安納です

おまけ:
PowerShellでリモート接続
手順
Step1:(サーバ側で)Enable-PSRemoting
Step2:(クライアント側で)WinRMクイック構成を有効にする
Step3:(クライアント側で)enter-pssession -ComputerName サーバ名 -Credential サーバ名\ユーザ名
※Windows Server 2012 R2 Essentialsのようにサーバがドメインに参加しているときは(ドメイン名)\(ユーザ名)

 参考:
PowerShellでリモートPCの操作を行うに為にEnable-PSRemotingをするための準備
PowerShell 2.0 ヒント集 > Windows PowerShell でリモート コマンドを有効にして使用する
seraphy / gist:4750882

以上


Viewing all articles
Browse latest Browse all 215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>