public override void ExecuteCmdlet() { // Fetch the hostname IotHubDescription iotHubDescription = this.IotHubClient.IotHubResource.Get(this.ResourceGroupName, this.Name); var hostName = iotHubDescription.Properties.HostName; if (KeyName != null) { SharedAccessSignatureAuthorizationRule authPolicy = this.IotHubClient.IotHubResource.GetKeysForKeyName(this.ResourceGroupName, this.Name, this.KeyName); this.WriteObject(authPolicy.ToPSIotHubConnectionString(hostName), false); } else { IEnumerable <SharedAccessSignatureAuthorizationRule> authPolicies = this.IotHubClient.IotHubResource.ListKeys(this.ResourceGroupName, this.Name); this.WriteObject(IotHubUtils.ToPSIotHubConnectionStrings(authPolicies, hostName), true); } }