public override void ExecuteCmdlet() { ProvisioningServiceDescription provisioningServiceDescription; if (ParameterSetName.Equals(InputObjectParameterSet)) { this.ResourceGroupName = this.DpsObject.ResourceGroupName; this.DpsName = this.DpsObject.Name; provisioningServiceDescription = IotDpsUtils.ConvertObject <PSProvisioningServiceDescription, ProvisioningServiceDescription>(this.DpsObject); } else { if (ParameterSetName.Equals(ResourceIdParameterSet)) { this.ResourceGroupName = IotDpsUtils.GetResourceGroupName(this.ResourceId); this.DpsName = IotDpsUtils.GetIotDpsName(this.ResourceId); } provisioningServiceDescription = GetIotDpsResource(this.ResourceGroupName, this.DpsName); } IEnumerable <SharedAccessSignatureAuthorizationRuleAccessRightsDescription> authPolicies = this.IotDpsClient.IotDpsResource.ListKeys(this.DpsName, this.ResourceGroupName); SharedAccessSignatureAuthorizationRuleAccessRightsDescription policy = IotDpsUtils.GetPolicy(authPolicies, PSAccessRightsDescription.EnrollmentWrite); PSIotDpsConnectionString psIotDpsConnectionString = IotDpsUtils.ToPSIotDpsConnectionString(policy, provisioningServiceDescription.Properties.ServiceOperationsHostName); ProvisioningServiceClient client = ProvisioningServiceClient.CreateFromConnectionString(psIotDpsConnectionString.PrimaryConnectionString); if ((!this.IsParameterBound(c => c.RegistrationId) && !this.IsParameterBound(c => c.EnrollmentId)) || (this.IsParameterBound(c => c.RegistrationId) && this.IsParameterBound(c => c.EnrollmentId))) { throw new ArgumentException("Please provide either RegistrationId or EnrollmentId."); } if (this.IsParameterBound(c => c.RegistrationId)) { DeviceRegistrationState result = client.GetDeviceRegistrationStateAsync(this.RegistrationId).GetAwaiter().GetResult(); this.WriteObject(IotDpsUtils.ToPSDeviceRegistrationState(result)); } if (this.IsParameterBound(c => c.EnrollmentId)) { string query = this.IsParameterBound(c => c.Query) ? this.Query : "select * from enrollments"; QueryResult results = client.CreateEnrollmentGroupRegistrationStateQuery(new QuerySpecification(query), this.EnrollmentId).NextAsync().GetAwaiter().GetResult(); this.WriteObject(IotDpsUtils.ToPSDeviceRegistrationStates(results.Items), true); } }