Ansible Privilege Escalation win_command – refresh Windows Update Service

When you have ansible deployed it is easy to perform massively actions on your inventory hosts. On a previous article I have explained in detail how you can easily manage Windows machines with Ansible.

In order to refresh Windows update service and make it connect to WSUS reporting console one should execute the below commands on a range of machines.

wuauclt /resetauthorization
wuauclt /reportnow
wuauclt /detectnow

In order to perform this task automated and avoid logging in on each machine, you can execute the below playbook.

- name: deploy commands on servers
 hosts: test
 become: true
 name: win_command resetauth
 win_command: wuauclt /resetauthorization
 name: win_command report
 win_command: wuauclt /reportnow
 name: win_command detect
 win_command: wuauclt /detectnow 

If you run this playbook without elevated privileges, it will fail. The necessary variables that must be included in your inventory or another appropriate location are listed below (folder variables, etc). The become keyword is a must but the escalation method must be changed instead of sudo as we handle windows machines.

 ansible_connection = winrm
 ansible_user = administrator

Get old events from Vcenter using powerCLI

If there is a reason that you want to retrieve older events from Vcenter than the 1000 that are available, you can use powerCLI in order to get specific date ranges.

After you login in the vCenter using

Connect-VIServer SERVER_IP

you can use Get-VIEvent with Start or Finish attributes. Be careful also to use Maxsamples attribute in order to get more than 10 that are returned by default.

For example if I wanted all events that have been captured the weekend I could use something like:

Get-VIEvent -maxsamples 10000 -start "28/07/2018"

P.S Date is a DateTime and should be used as above