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 18944344885d7e1265e5d4d_000000…