Skip to content

Instantly share code, notes, and snippets.

@tas50
Created June 19, 2017 22:28
Show Gist options
  • Save tas50/2ea40cf95503aff28ae29d418bbdccef to your computer and use it in GitHub Desktop.
Save tas50/2ea40cf95503aff28ae29d418bbdccef to your computer and use it in GitHub Desktop.
Windows Updates in Ohai
Ohai.plugin :WindowsPatches do
provides "windowspatches"
collect_data :windows do
windowspatches Mash.new
patch_data = shell_out('powershell.exe -NoLogo -NonInteractive -NoProfile -command "Get-HotFix | ConvertTo-Json"')
parser = FFI_Yajl::Parser.new
windowspatches["updates"] = []
windowspatches["details"] = Mash.new
parser.parse(patch_data.stdout).each do |update|
windowspatches["updates"] << update["HotFixID"]
windowspatches["details"][update["HotFixID"]] = Mash.new
windowspatches["details"][update["HotFixID"]]["description"] = update["Description"]
windowspatches["details"][update["HotFixID"]]["install_date"] = update["InstalledOn"]["DateTime"]
end
end
end
@tas50
Copy link
Author

tas50 commented Jun 19, 2017

Output:

"windowspatches": {
  "updates": [
    "KB2919355",
    "KB2919442",
    "KB2937220",
    "KB2938772",
    "KB2939471",
    "KB2949621"
  ],
  "details": {
    "KB2919355": {
      "description": "Update",
      "install_date": "Friday, March 21, 2014 12:00:00 AM"
    },
    "KB2919442": {
      "description": "Update",
      "install_date": "Friday, March 21, 2014 12:00:00 AM"
    },
    "KB2937220": {
      "description": "Update",
      "install_date": "Friday, March 21, 2014 12:00:00 AM"
    },
    "KB2938772": {
      "description": "Update",
      "install_date": "Friday, March 21, 2014 12:00:00 AM"
    },
    "KB2939471": {
      "description": "Update",
      "install_date": "Friday, March 21, 2014 12:00:00 AM"
    },
    "KB2949621": {
      "description": "Hotfix",
      "install_date": "Friday, March 21, 2014 12:00:00 AM"
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment