From 2ca73a404ab575d824933c6402c32f450dceb5c6 Mon Sep 17 00:00:00 2001 From: Gautam Sheth Date: Thu, 12 Oct 2023 17:18:15 +0300 Subject: [PATCH 1/2] Feature: add GCC support for some cmdlets --- CHANGELOG.md | 1 + src/Commands/AzureAD/GetAzureADUser.cs | 8 ++++---- .../PowerPlatform/PowerAutomate/AddFlowOwner.cs | 4 ++-- .../PowerAutomate/RemoveFlowOwner.cs | 4 ++-- ...PointUserProfilesFromAzureActiveDirectory.cs | 2 +- src/Commands/Utilities/AzureAdUtility.cs | 17 +++++++++-------- 6 files changed, 19 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cf4af2ff..661b8b28a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Added option to create a Microsoft 365 Group with dynamic membership by passing in `-DynamicMembershipRule` [#3426](https://github.com/pnp/powershell/pull/3426) - Added `RestrictedAccessControl`, `ClearRestrictedAccessControl`, `RemoveRestrictedAccessControlGroups`, `AddRestrictedAccessControlGroups` and `RestrictedAccessControlGroups` parameters to `Set-PnPTenantSite` cmdlet to handle restricted access control. [#3463](https://github.com/pnp/powershell/pull/3463) - Added `Get-PnPRetentionLabel` cmdlet to retrieve Purview retention labels. [#3459](https://github.com/pnp/powershell/pull/3459) +- Added GCC support for `Get-PnPAzureADUser` , `Add-PnPFlowOwner` , `Remove-PnPFlowOwner` and `Sync-PnPSharePointUserProfilesFromAzureActiveDirectory` cmdlets ### Fixed diff --git a/src/Commands/AzureAD/GetAzureADUser.cs b/src/Commands/AzureAD/GetAzureADUser.cs index 651b71c25..b906e4035 100644 --- a/src/Commands/AzureAD/GetAzureADUser.cs +++ b/src/Commands/AzureAD/GetAzureADUser.cs @@ -69,22 +69,22 @@ protected override void ExecuteCmdlet() PnP.PowerShell.Commands.Model.AzureAD.User user; if (Guid.TryParse(Identity, out Guid identityGuid)) { - user = PnP.PowerShell.Commands.Utilities.AzureAdUtility.GetUser(AccessToken, identityGuid, ignoreDefaultProperties: IgnoreDefaultProperties, useBetaEndPoint: UseBeta.IsPresent); + user = PnP.PowerShell.Commands.Utilities.AzureAdUtility.GetUser(AccessToken, identityGuid, ignoreDefaultProperties: IgnoreDefaultProperties, useBetaEndPoint: UseBeta.IsPresent, azureEnvironment: Connection.AzureEnvironment); } else { - user = PnP.PowerShell.Commands.Utilities.AzureAdUtility.GetUser(AccessToken, WebUtility.UrlEncode(Identity), Select, ignoreDefaultProperties: IgnoreDefaultProperties, useBetaEndPoint: UseBeta.IsPresent); + user = PnP.PowerShell.Commands.Utilities.AzureAdUtility.GetUser(AccessToken, WebUtility.UrlEncode(Identity), Select, ignoreDefaultProperties: IgnoreDefaultProperties, useBetaEndPoint: UseBeta.IsPresent, azureEnvironment: Connection.AzureEnvironment); } WriteObject(user); } else if (ParameterSpecified(nameof(Delta))) { - var userDelta = PnP.PowerShell.Commands.Utilities.AzureAdUtility.ListUserDelta(AccessToken, DeltaToken, Filter, OrderBy, Select, StartIndex, EndIndex, useBetaEndPoint: UseBeta.IsPresent); + var userDelta = PnP.PowerShell.Commands.Utilities.AzureAdUtility.ListUserDelta(AccessToken, DeltaToken, Filter, OrderBy, Select, StartIndex, EndIndex, useBetaEndPoint: UseBeta.IsPresent, azureEnvironment: Connection.AzureEnvironment); WriteObject(userDelta); } else { - var users = PnP.PowerShell.Commands.Utilities.AzureAdUtility.ListUsers(AccessToken, Filter, OrderBy, Select, ignoreDefaultProperties: IgnoreDefaultProperties, StartIndex, EndIndex, useBetaEndPoint: UseBeta.IsPresent); + var users = PnP.PowerShell.Commands.Utilities.AzureAdUtility.ListUsers(AccessToken, Filter, OrderBy, Select, ignoreDefaultProperties: IgnoreDefaultProperties, StartIndex, EndIndex, useBetaEndPoint: UseBeta.IsPresent, azureEnvironment: Connection.AzureEnvironment); WriteObject(users, true); } } diff --git a/src/Commands/PowerPlatform/PowerAutomate/AddFlowOwner.cs b/src/Commands/PowerPlatform/PowerAutomate/AddFlowOwner.cs index 5570219f0..8270eb717 100644 --- a/src/Commands/PowerPlatform/PowerAutomate/AddFlowOwner.cs +++ b/src/Commands/PowerPlatform/PowerAutomate/AddFlowOwner.cs @@ -49,12 +49,12 @@ protected override void ExecuteCmdlet() if (Guid.TryParse(User, out Guid identityGuid)) { WriteVerbose("Looking up user through Microsoft Graph by user id {identityGuid}"); - user = Utilities.AzureAdUtility.GetUser(graphAccessToken, identityGuid); + user = Utilities.AzureAdUtility.GetUser(graphAccessToken, identityGuid, azureEnvironment: Connection.AzureEnvironment); } else { WriteVerbose($"Looking up user through Microsoft Graph by user principal name {User}"); - user = Utilities.AzureAdUtility.GetUser(graphAccessToken, WebUtility.UrlEncode(User)); + user = Utilities.AzureAdUtility.GetUser(graphAccessToken, WebUtility.UrlEncode(User), azureEnvironment: Connection.AzureEnvironment); } if (user == null) diff --git a/src/Commands/PowerPlatform/PowerAutomate/RemoveFlowOwner.cs b/src/Commands/PowerPlatform/PowerAutomate/RemoveFlowOwner.cs index 4adb963f1..2a229bfa5 100644 --- a/src/Commands/PowerPlatform/PowerAutomate/RemoveFlowOwner.cs +++ b/src/Commands/PowerPlatform/PowerAutomate/RemoveFlowOwner.cs @@ -49,12 +49,12 @@ protected override void ExecuteCmdlet() if (Guid.TryParse(User, out Guid identityGuid)) { WriteVerbose("Looking up user through Microsoft Graph by user id {identityGuid}"); - user = Utilities.AzureAdUtility.GetUser(graphAccessToken, identityGuid); + user = Utilities.AzureAdUtility.GetUser(graphAccessToken, identityGuid, azureEnvironment: Connection.AzureEnvironment); } else { WriteVerbose($"Looking up user through Microsoft Graph by user principal name {User}"); - user = Utilities.AzureAdUtility.GetUser(graphAccessToken, WebUtility.UrlEncode(User)); + user = Utilities.AzureAdUtility.GetUser(graphAccessToken, WebUtility.UrlEncode(User), azureEnvironment: Connection.AzureEnvironment); } if (user == null) diff --git a/src/Commands/UserProfiles/SyncSharePointUserProfilesFromAzureActiveDirectory.cs b/src/Commands/UserProfiles/SyncSharePointUserProfilesFromAzureActiveDirectory.cs index f2112355c..56d6d88bb 100644 --- a/src/Commands/UserProfiles/SyncSharePointUserProfilesFromAzureActiveDirectory.cs +++ b/src/Commands/UserProfiles/SyncSharePointUserProfilesFromAzureActiveDirectory.cs @@ -76,7 +76,7 @@ protected override void ExecuteCmdlet() WriteVerbose("Retrieving users from Azure Active Directory"); // Retrieve all the users from Azure Active Directory - aadUsers = PnP.PowerShell.Commands.Utilities.AzureAdUtility.ListUsers(GraphAccessToken, null, null, allAadPropertiesList.ToArray(), endIndex: null); + aadUsers = PnP.PowerShell.Commands.Utilities.AzureAdUtility.ListUsers(GraphAccessToken, null, null, allAadPropertiesList.ToArray(), endIndex: null, azureEnvironment: Connection.AzureEnvironment); WriteVerbose($"{aadUsers.Count} user{(aadUsers.Count != 1 ? "s have" : " has")} been retrieved from Azure Active Directory"); diff --git a/src/Commands/Utilities/AzureAdUtility.cs b/src/Commands/Utilities/AzureAdUtility.cs index 20c31b769..0358ab8e0 100644 --- a/src/Commands/Utilities/AzureAdUtility.cs +++ b/src/Commands/Utilities/AzureAdUtility.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using PnP.Framework; using PnP.PowerShell.Commands.Model.AzureAD; namespace PnP.PowerShell.Commands.Utilities @@ -24,9 +25,9 @@ internal static class AzureAdUtility /// Optional end index indicating up to which result to return users. By default all users will be returned. /// Indicates if the v1.0 (false) or beta (true) endpoint should be used at Microsoft Graph to query for the data /// UserDelta instance - public static UserDelta ListUserDelta(string accessToken, string deltaToken, string filter, string orderby, string[] selectProperties = null, int startIndex = 0, int? endIndex = null, bool useBetaEndPoint = false) + public static UserDelta ListUserDelta(string accessToken, string deltaToken, string filter, string orderby, string[] selectProperties = null, int startIndex = 0, int? endIndex = null, bool useBetaEndPoint = false, AzureEnvironment azureEnvironment = AzureEnvironment.Production) { - var userDelta = PnP.Framework.Graph.UsersUtility.ListUserDelta(accessToken, deltaToken, filter, orderby, selectProperties, startIndex, endIndex, useBetaEndPoint: useBetaEndPoint); + var userDelta = PnP.Framework.Graph.UsersUtility.ListUserDelta(accessToken, deltaToken, filter, orderby, selectProperties, startIndex, endIndex, useBetaEndPoint: useBetaEndPoint, azureEnvironment: azureEnvironment); var result = new UserDelta { @@ -48,9 +49,9 @@ public static UserDelta ListUserDelta(string accessToken, string deltaToken, str /// Last item in the results returned by Microsoft Graph to return. Provide NULL to return all results that exist. /// Indicates if the v1.0 (false) or beta (true) endpoint should be used at Microsoft Graph to query for the data /// List with User objects - public static List ListUsers(string accessToken, string filter, string orderby, string[] selectProperties = null, bool ignoreDefaultProperties = false, int startIndex = 0, int? endIndex = 999, bool useBetaEndPoint = false) + public static List ListUsers(string accessToken, string filter, string orderby, string[] selectProperties = null, bool ignoreDefaultProperties = false, int startIndex = 0, int? endIndex = 999, bool useBetaEndPoint = false, AzureEnvironment azureEnvironment = AzureEnvironment.Production) { - return PnP.Framework.Graph.UsersUtility.ListUsers(accessToken, filter, orderby, selectProperties, startIndex, endIndex, ignoreDefaultProperties: ignoreDefaultProperties, useBetaEndPoint: useBetaEndPoint).Select(User.CreateFrom).ToList(); + return PnP.Framework.Graph.UsersUtility.ListUsers(accessToken, filter, orderby, selectProperties, startIndex, endIndex, ignoreDefaultProperties: ignoreDefaultProperties, useBetaEndPoint: useBetaEndPoint, azureEnvironment: azureEnvironment).Select(User.CreateFrom).ToList(); } /// @@ -64,9 +65,9 @@ public static List ListUsers(string accessToken, string filter, string ord /// Last item in the results returned by Microsoft Graph to return. Provide NULL to return all results that exist. /// Indicates if the v1.0 (false) or beta (true) endpoint should be used at Microsoft Graph to query for the data /// List with User objects - public static User GetUser(string accessToken, Guid userId, string[] selectProperties = null, bool ignoreDefaultProperties = false, int startIndex = 0, int? endIndex = 999, bool useBetaEndPoint = false) + public static User GetUser(string accessToken, Guid userId, string[] selectProperties = null, bool ignoreDefaultProperties = false, int startIndex = 0, int? endIndex = 999, bool useBetaEndPoint = false, AzureEnvironment azureEnvironment = AzureEnvironment.Production) { - return PnP.Framework.Graph.UsersUtility.ListUsers(accessToken, $"id eq '{userId}'", null, selectProperties, startIndex, endIndex, ignoreDefaultProperties: ignoreDefaultProperties, useBetaEndPoint: useBetaEndPoint).Select(User.CreateFrom).FirstOrDefault(); + return PnP.Framework.Graph.UsersUtility.ListUsers(accessToken, $"id eq '{userId}'", null, selectProperties, startIndex, endIndex, ignoreDefaultProperties: ignoreDefaultProperties, useBetaEndPoint: useBetaEndPoint, azureEnvironment: azureEnvironment).Select(User.CreateFrom).FirstOrDefault(); } /// @@ -80,9 +81,9 @@ public static User GetUser(string accessToken, Guid userId, string[] selectPrope /// Last item in the results returned by Microsoft Graph to return. Provide NULL to return all results that exist. /// Indicates if the v1.0 (false) or beta (true) endpoint should be used at Microsoft Graph to query for the data /// User object - public static User GetUser(string accessToken, string userPrincipalName, string[] selectProperties = null, bool ignoreDefaultProperties = false, int startIndex = 0, int? endIndex = 999, bool useBetaEndPoint = false) + public static User GetUser(string accessToken, string userPrincipalName, string[] selectProperties = null, bool ignoreDefaultProperties = false, int startIndex = 0, int? endIndex = 999, bool useBetaEndPoint = false, AzureEnvironment azureEnvironment = AzureEnvironment.Production) { - return PnP.Framework.Graph.UsersUtility.ListUsers(accessToken, $"userPrincipalName eq '{userPrincipalName}'", null, selectProperties, startIndex, endIndex, ignoreDefaultProperties: ignoreDefaultProperties, useBetaEndPoint: useBetaEndPoint).Select(User.CreateFrom).FirstOrDefault(); + return PnP.Framework.Graph.UsersUtility.ListUsers(accessToken, $"userPrincipalName eq '{userPrincipalName}'", null, selectProperties, startIndex, endIndex, ignoreDefaultProperties: ignoreDefaultProperties, useBetaEndPoint: useBetaEndPoint, azureEnvironment: azureEnvironment).Select(User.CreateFrom).FirstOrDefault(); } #endregion From 60839fd64902d049314bc0e498c0e7130a138b78 Mon Sep 17 00:00:00 2001 From: Gautam Sheth Date: Fri, 13 Oct 2023 16:40:04 +0300 Subject: [PATCH 2/2] Additional cmdlet support for GCC --- CHANGELOG.md | 2 +- .../AzureAD/NewAzureADUserTemporaryAccessPass.cs | 2 +- src/Commands/Base/PipeBinds/AzureADUserPipeBind.cs | 10 ++++++---- src/Commands/Purview/GetAvailableSensitivityLabel.cs | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 661b8b28a..c392eb5c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,7 +35,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Added option to create a Microsoft 365 Group with dynamic membership by passing in `-DynamicMembershipRule` [#3426](https://github.com/pnp/powershell/pull/3426) - Added `RestrictedAccessControl`, `ClearRestrictedAccessControl`, `RemoveRestrictedAccessControlGroups`, `AddRestrictedAccessControlGroups` and `RestrictedAccessControlGroups` parameters to `Set-PnPTenantSite` cmdlet to handle restricted access control. [#3463](https://github.com/pnp/powershell/pull/3463) - Added `Get-PnPRetentionLabel` cmdlet to retrieve Purview retention labels. [#3459](https://github.com/pnp/powershell/pull/3459) -- Added GCC support for `Get-PnPAzureADUser` , `Add-PnPFlowOwner` , `Remove-PnPFlowOwner` and `Sync-PnPSharePointUserProfilesFromAzureActiveDirectory` cmdlets +- Added GCC support for `Get-PnPAzureADUser` , `Add-PnPFlowOwner` , `Remove-PnPFlowOwner`, `Sync-PnPSharePointUserProfilesFromAzureActiveDirectory`, `New-PnPAzureADUserTemporaryAccessPass` and `Get-PnPAvailableSensitivityLabel` cmdlets. [#3484](https://github.com/pnp/powershell/pull/3484) ### Fixed diff --git a/src/Commands/AzureAD/NewAzureADUserTemporaryAccessPass.cs b/src/Commands/AzureAD/NewAzureADUserTemporaryAccessPass.cs index 7138d5a8d..3e6b59b0d 100644 --- a/src/Commands/AzureAD/NewAzureADUserTemporaryAccessPass.cs +++ b/src/Commands/AzureAD/NewAzureADUserTemporaryAccessPass.cs @@ -30,7 +30,7 @@ protected override void ExecuteCmdlet() userId: Identity.User?.Id?.ToString() ?? Identity.Upn ?? Identity.UserId, startDateTime: StartDateTime, lifeTimeInMinutes: LifeTimeInMinutes, - isUsableOnce: IsUsableOnce); + isUsableOnce: IsUsableOnce, azureEnvironment: Connection.AzureEnvironment); WriteObject(accessPass); } diff --git a/src/Commands/Base/PipeBinds/AzureADUserPipeBind.cs b/src/Commands/Base/PipeBinds/AzureADUserPipeBind.cs index b22e79c92..466b4f373 100644 --- a/src/Commands/Base/PipeBinds/AzureADUserPipeBind.cs +++ b/src/Commands/Base/PipeBinds/AzureADUserPipeBind.cs @@ -1,4 +1,5 @@ -using PnP.PowerShell.Commands.Model.AzureAD; +using PnP.Framework; +using PnP.PowerShell.Commands.Model.AzureAD; using System; using System.Net; @@ -54,8 +55,9 @@ public AzureADUserPipeBind(string input) /// Tries to return the User instace based on the information this pipe has available /// /// Access Token for Microsoft Graph that can be used to fetch User data + /// Azure environment cloud /// User instance or NULL if unable to define user instance based on the available information - public User GetUser(string accessToken) + public User GetUser(string accessToken, AzureEnvironment azureEnvironment = AzureEnvironment.Production) { if (_user != null) { @@ -63,11 +65,11 @@ public User GetUser(string accessToken) } if (_userId != null) { - return User.CreateFrom(PnP.Framework.Graph.UsersUtility.GetUser(accessToken, _userId)); + return User.CreateFrom(PnP.Framework.Graph.UsersUtility.GetUser(accessToken, _userId, azureEnvironment: azureEnvironment)); } if (_upn != null) { - return User.CreateFrom(PnP.Framework.Graph.UsersUtility.GetUser(accessToken, WebUtility.UrlEncode(_upn))); + return User.CreateFrom(PnP.Framework.Graph.UsersUtility.GetUser(accessToken, WebUtility.UrlEncode(_upn), azureEnvironment: azureEnvironment)); } return null; } diff --git a/src/Commands/Purview/GetAvailableSensitivityLabel.cs b/src/Commands/Purview/GetAvailableSensitivityLabel.cs index f1debcd91..bd171bf87 100644 --- a/src/Commands/Purview/GetAvailableSensitivityLabel.cs +++ b/src/Commands/Purview/GetAvailableSensitivityLabel.cs @@ -23,7 +23,7 @@ protected override void ExecuteCmdlet() string url; if (ParameterSpecified(nameof(User))) { - var user = User.GetUser(AccessToken); + var user = User.GetUser(AccessToken, Connection.AzureEnvironment); if (user == null) {