function Write-Log { param ( [string]$Message, [string]$LogPath = "$env:TEMP\getscancab.log" ) $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" $entry = "[$timestamp] $Message" Add-Content -Path $LogPath -Value $entry } $LogPath = "<ログの保存先パス>\getscancab.log" Write-Log -Message "Check the latest wsusscn2.cab." -LogPath $LogPath $scancabCurrent = "<更新カタログファイルの保存先パス>\wsusscn2.cab" $scancabTemp = "$env:TEMP\wsusscn2.cab" #https://go.microsoft.com/fwlink/?LinkID=74689 # -> https://catalog.s.download.windowsupdate.com/microsoftupdate/v6/wsusscan/wsusscn2.cab Invoke-WebRequest -uri https://go.microsoft.com/fwlink/?LinkID=74689 -outfile $scancabTemp -UseBasicParsing if (Test-Path $scancabCurrent) { if ((Get-Item $scancabTemp).Length -eq (Get-Item $scancabCurrent).Length) { Remove-Item $scancabTemp -Force Write-Log -Message "Current wsusscn2.cab is up-to-date." -LogPath $LogPath } else { Remove-Item $scancabCurrent -Force Move-Item -Path $scancabTemp -Destination $scancabCurrent Write-Log -Message "Updated to the latest wsusscn2.cab." -LogPath $LogPath } } else { Move-Item -Path $scancabTemp -Destination $scancabCurrent Write-Log -Message "Downloaded to the latest wsusscn2.cab." -LogPath $LogPath }