I was getting permissions errors from Line 171 $graph = Connect-MgGraph -Scopes DeviceManagementConfiguration.Read.All, DeviceManagementApps.ReadWrite.All update this to $graph = Connect-MgGraph -Scopes DeviceManagementConfiguration.Read.All, DeviceManagementApps.Read.All, DeviceManagementServiceConfig.Read.All, group.read.all removes the write permissions and allows the autopilot and enrollment to work and also allows you to read groups