protected override void ExecuteCmdlet() { EnsureSubscription(ContentTypeString); var url = $"{ApiUrl}/subscriptions/content?contentType={ContentTypeString}&PublisherIdentifier=${Token.TenantId}"; if (StartTime != DateTime.MinValue) { url += $"&startTime={StartTime:yyyy-MM-ddThh:mm:ss}"; } if (EndTime != DateTime.MaxValue) { url += $"&endTime={EndTime:yyyy-MM-ddThh:mm:ss}"; } var res = GraphHttpClient.MakeGetRequestForString(url.ToString(), AccessToken); if (!string.IsNullOrEmpty(res)) { var contents = JsonConvert.DeserializeObject <IEnumerable <ManagementApiSubscriptionContent> >(res); foreach (var content in contents) { res = GraphHttpClient.MakeGetRequestForString(content.ContentUri, AccessToken); var logs = JsonConvert.DeserializeObject <IEnumerable <ManagementApiUnifiedLogRecord> >(res); WriteObject(logs, true); } } }
protected override void ExecuteCmdlet() { var response = GraphHttpClient.MakeGetRequestForString($"{ApiRootUrl}ServiceComms/Messages{(ParameterSpecified(nameof(Workload)) ? $"?$filter=Workload eq '{Workload.Value}'" : "")}", AccessToken); var servicesJson = JObject.Parse(response); var services = servicesJson["value"].ToObject <IEnumerable <ManagementApiServiceMessage> >(); WriteObject(services, true); }
protected override void ExecuteCmdlet() { var response = GraphHttpClient.MakeGetRequestForString($"{ApiRootUrl}ServiceComms/Services", AccessToken); var servicesJson = JObject.Parse(response); var services = servicesJson["value"].ToObject <IEnumerable <ManagementApiService> >(); WriteObject(services, true); }
private IEnumerable <ManagementApiSubscription> GetSubscriptions() { var url = $"{ApiUrl}/subscriptions/list"; var res = GraphHttpClient.MakeGetRequestForString(url.ToString(), AccessToken); var subscriptions = JsonConvert.DeserializeObject <IEnumerable <ManagementApiSubscription> >(res); return(subscriptions); }
public static TokenParser ProcessO365GroupSettings(Tenant tenant, ProvisioningTenant provisioningTenant, TokenParser parser, PnPMonitoredScope scope, ProvisioningMessagesDelegate messagesDelegate) { if (provisioningTenant.Office365GroupsSettings != null && provisioningTenant.Office365GroupsSettings.Properties.Any()) { messagesDelegate?.Invoke("Processing Office 365 Group Settings", ProvisioningMessageType.Progress); bool siteClassificationSettingsExists = false; if (PnPProvisioningContext.Current != null) { string accessToken = string.Empty; try { // Get a fresh Access Token for every request accessToken = PnPProvisioningContext.Current.AcquireToken(GraphHelper.MicrosoftGraphBaseURI, "Directory.ReadWrite.All"); if (accessToken != null) { try { var siteClassificationSettings = tenant.GetSiteClassificationsSettings(accessToken); siteClassificationSettingsExists = true; } catch (Exception ex) { // Tenant classification doesn't exist, just swallow the exception. } if (siteClassificationSettingsExists) { // Tenant classification exists, update the necessary values for Group Settings. try { string directorySettingTemplatesUrl = $"{GraphHttpClient.MicrosoftGraphV1BaseUri}groupSettings"; var directorySettingTemplatesJson = GraphHttpClient.MakeGetRequestForString(directorySettingTemplatesUrl, accessToken); var directorySettingTemplates = JsonConvert.DeserializeObject <DirectorySettingTemplates>(directorySettingTemplatesJson); // Retrieve the setinngs for "Group.Unified" var unifiedGroupSetting = directorySettingTemplates.Templates.FirstOrDefault(t => t.DisplayName == "Group.Unified"); if (unifiedGroupSetting != null) { var props = provisioningTenant.Office365GroupsSettings.Properties; foreach (var v in unifiedGroupSetting.SettingValues) { var item = props.Where(p => p.Key == v.Name).FirstOrDefault(); if (!string.IsNullOrEmpty(item.Key)) { v.Value = parser.ParseString(item.Value); } } string updateDirectorySettingUrl = $"{GraphHttpClient.MicrosoftGraphV1BaseUri}groupSettings/{unifiedGroupSetting.Id}"; var updateDirectorySettingResult = GraphHttpClient.MakePatchRequestForString( updateDirectorySettingUrl, content: new { templateId = unifiedGroupSetting.Id, values = from v in unifiedGroupSetting.SettingValues select new { name = v.Name, value = v.Value }, }, contentType: "application/json", accessToken: accessToken); } else { throw new ApplicationException("Missing DirectorySettingTemplate for \"Group.Unified\""); } } catch (Exception ex) { scope.LogError($"Error occurred processing O365 Group settings ${ex.Message}"); } } else { // Tenant classification doesn't exist, create the necessary template for Group Settings. try { string directorySettingTemplatesUrl = $"{GraphHttpClient.MicrosoftGraphV1BaseUri}groupSettingTemplates"; var directorySettingTemplatesJson = GraphHttpClient.MakeGetRequestForString(directorySettingTemplatesUrl, accessToken); var directorySettingTemplates = JsonConvert.DeserializeObject <DirectorySettingTemplates>(directorySettingTemplatesJson); // Retrieve the setinngs for "Group.Unified" var unifiedGroupSetting = directorySettingTemplates.Templates.FirstOrDefault(t => t.DisplayName == "Group.Unified"); if (unifiedGroupSetting != null) { var props = provisioningTenant.Office365GroupsSettings.Properties; foreach (var v in unifiedGroupSetting.SettingValues) { var item = props.Where(p => p.Key == v.Name).FirstOrDefault(); if (!string.IsNullOrEmpty(item.Key)) { v.Value = parser.ParseString(item.Value); } else { // Set default value because null is not supported // It only accepts entire collection and not individual properties v.Value = v.DefaultValue; } } string updateDirectorySettingUrl = $"{GraphHttpClient.MicrosoftGraphV1BaseUri}groupSettings"; var updateDirectorySettingResult = GraphHttpClient.MakePostRequestForString( updateDirectorySettingUrl, content: new { templateId = unifiedGroupSetting.Id, values = from v in unifiedGroupSetting.SettingValues select new { name = v.Name, value = v.Value }, }, contentType: "application/json", accessToken: accessToken); } else { throw new ApplicationException("Missing DirectorySettingTemplate for \"Group.Unified\""); } } catch (Exception ex) { scope.LogError($"Error occurred processing O365 Group settings ${ex.Message}"); } } } } catch (Exception ex) { scope.LogError($"Error occurred processing O365 Group settings ${ex.Message}"); } } } return(parser); }