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 12291518025f306c8b8cd6b_000000…