EXCEPTION_ACCESS_VIOLATION when working with Availability Groups

My colleague was dealing with a request from another member of IT today – they’re currently automating the process of patching, and as such some permissions were needed for the service account dealing with the automation jobs. Specifically they needed control of the Availability Group object – so my colleague ran the following code 5842348505dd45d4775008_000000…