From fa3915854308b6db36a46e3f0f3b4ad78ba68d65 Mon Sep 17 00:00:00 2001 From: Steve Mutungi <132555836+SteveMutungi254@users.noreply.github.com> Date: Tue, 1 Apr 2025 10:17:37 +0300 Subject: [PATCH 1/7] Adding alias + adding input validations --- .../Users/Get-EntraDeletedUser.ps1 | 10 ++++++++- .../Microsoft.Entra/Users/Get-EntraUser.ps1 | 14 ++++++------ .../Users/Get-EntraUserAdministrativeUnit.ps1 | 12 ++++++++-- .../Users/Get-EntraUserAppRoleAssignment.ps1 | 18 ++++++++++----- .../Users/Get-EntraUserCreatedObject.ps1 | 10 ++++++++- .../Users/Get-EntraUserDirectReport.ps1 | 18 ++++++++++----- .../Users/Get-EntraUserExtension.ps1 | 14 +++++++++--- .../Users/Get-EntraUserGroup.ps1 | 10 ++++++++- .../Users/Get-EntraUserLicenseDetail.ps1 | 16 ++++++++++---- .../Users/Get-EntraUserManager.ps1 | 14 +++++++++--- .../Users/Get-EntraUserMembership.ps1 | 20 ++++++++++++----- .../Get-EntraUserOAuth2PermissionGrant.ps1 | 20 ++++++++++++----- .../Users/Get-EntraUserOwnedDevice.ps1 | 18 ++++++++++----- .../Users/Get-EntraUserOwnedObject.ps1 | 18 ++++++++++----- .../Users/Get-EntraUserRegisteredDevice.ps1 | 10 ++++++++- .../Users/Get-EntraUserRole.ps1 | 12 ++++++++-- .../Users/Get-EntraUserSponsor.ps1 | 9 ++++++++ .../Users/Get-EntraUserThumbnailPhoto.ps1 | 22 +++++++++++++------ .../Users/Get-EntraBetaDeletedUser.ps1 | 10 ++++++++- .../Users/Get-EntraBetaUser.ps1 | 14 ++++++------ .../Get-EntraBetaUserAdministrativeUnit.ps1 | 12 ++++++++-- .../Get-EntraBetaUserAppRoleAssignment.ps1 | 16 ++++++++++---- .../Users/Get-EntraBetaUserCreatedObject.ps1 | 10 ++++++++- .../Users/Get-EntraBetaUserDirectReport.ps1 | 16 ++++++++++---- .../Users/Get-EntraBetaUserExtension.ps1 | 14 +++++++++--- .../Users/Get-EntraBetaUserGroup.ps1 | 10 ++++++++- .../Users/Get-EntraBetaUserLicenseDetail.ps1 | 16 ++++++++++---- .../Users/Get-EntraBetaUserManager.ps1 | 14 +++++++++--- .../Users/Get-EntraBetaUserMembership.ps1 | 18 ++++++++++----- ...Get-EntraBetaUserOAuth2PermissionGrant.ps1 | 16 ++++++++++---- .../Users/Get-EntraBetaUserOwnedDevice.ps1 | 16 ++++++++++---- .../Users/Get-EntraBetaUserOwnedObject.ps1 | 16 ++++++++++---- .../Get-EntraBetaUserRegisteredDevice.ps1 | 10 ++++++++- .../Users/Get-EntraBetaUserRole.ps1 | 12 ++++++++-- .../Users/Get-EntraBetaUserSponsor.ps1 | 9 ++++++++ .../Users/Get-EntraBetaUserThumbnailPhoto.ps1 | 22 +++++++++++++------ .../Users/Get-EntraBetaDeletedUser.md | 2 +- .../Users/Get-EntraBetaUser.md | 2 +- .../Get-EntraBetaUserAdministrativeUnit.md | 16 ++++++++++++++ .../Get-EntraBetaUserAppRoleAssignment.md | 2 +- .../Users/Get-EntraBetaUserCreatedObject.md | 2 +- .../Users/Get-EntraBetaUserDirectReport.md | 2 +- .../Users/Get-EntraBetaUserExtension.md | 4 ++-- .../Users/Get-EntraBetaUserGroup.md | 16 ++++++++++++++ .../Users/Get-EntraBetaUserLicenseDetail.md | 4 ++-- .../Users/Get-EntraBetaUserManager.md | 4 ++-- .../Users/Get-EntraBetaUserMembership.md | 2 +- .../Get-EntraBetaUserOAuth2PermissionGrant.md | 2 +- .../Users/Get-EntraBetaUserOwnedDevice.md | 2 +- .../Users/Get-EntraBetaUserOwnedObject.md | 2 +- .../Get-EntraBetaUserRegisteredDevice.md | 2 +- .../Users/Get-EntraBetaUserRole.md | 16 ++++++++++++++ .../Users/Get-EntraBetaUserSponsor.md | 1 + .../Users/Get-EntraBetaUserThumbnailPhoto.md | 2 +- .../Users/Get-EntraDeletedUser.md | 2 +- .../Users/Get-EntraUser.md | 2 +- .../Users/Get-EntraUserAdministrativeUnit.md | 16 ++++++++++++++ .../Users/Get-EntraUserAppRoleAssignment.md | 2 +- .../Users/Get-EntraUserCreatedObject.md | 2 +- .../Users/Get-EntraUserDirectReport.md | 2 +- .../Users/Get-EntraUserExtension.md | 2 +- .../Users/Get-EntraUserGroup.md | 16 ++++++++++++++ .../Users/Get-EntraUserLicenseDetail.md | 4 ++-- .../Users/Get-EntraUserManager.md | 4 ++-- .../Users/Get-EntraUserMembership.md | 2 +- .../Get-EntraUserOAuth2PermissionGrant.md | 2 +- .../Users/Get-EntraUserOwnedDevice.md | 2 +- .../Users/Get-EntraUserOwnedObject.md | 2 +- .../Users/Get-EntraUserRegisteredDevice.md | 2 +- .../Users/Get-EntraUserRole.md | 16 ++++++++++++++ .../Users/Get-EntraUserSponsor.md | 1 + .../Users/Get-EntraUserThumbnailPhoto.md | 2 +- 72 files changed, 526 insertions(+), 154 deletions(-) diff --git a/module/Entra/Microsoft.Entra/Users/Get-EntraDeletedUser.ps1 b/module/Entra/Microsoft.Entra/Users/Get-EntraDeletedUser.ps1 index 5e12b089a9..1fc8c3b2c4 100644 --- a/module/Entra/Microsoft.Entra/Users/Get-EntraDeletedUser.ps1 +++ b/module/Entra/Microsoft.Entra/Users/Get-EntraDeletedUser.ps1 @@ -14,8 +14,16 @@ function Get-EntraDeletedUser { [Parameter(ParameterSetName = "GetVague", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Search string to use for vague queries.")] [System.String] $SearchString, - [Alias('Id')] [Parameter(ParameterSetName = "GetById", Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "ID of the user to retrieve.")] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserId must be a valid email address or GUID." + })] [System.String] $UserId, [Alias('Limit')] diff --git a/module/Entra/Microsoft.Entra/Users/Get-EntraUser.ps1 b/module/Entra/Microsoft.Entra/Users/Get-EntraUser.ps1 index 1d878d61c3..08d30babe3 100644 --- a/module/Entra/Microsoft.Entra/Users/Get-EntraUser.ps1 +++ b/module/Entra/Microsoft.Entra/Users/Get-EntraUser.ps1 @@ -6,24 +6,24 @@ function Get-EntraUser { [CmdletBinding(DefaultParameterSetName = 'GetQuery')] [Alias("Get-AzureADUser")] param ( - [Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Maximum number of results to return.")] [Alias("Limit")] [System.Nullable`1[System.Int32]] $Top, - [Alias("ObjectId")] - [Parameter(ParameterSetName = "GetById", Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [Parameter(ParameterSetName = "GetById", Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Specifies the ID of a user (as a UserPrincipalName or ObjectId) in Microsoft Entra ID.")] [System.String] $UserId, - [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Return all users.")] [switch] $All, - [Parameter(ParameterSetName = "GetVague", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(ParameterSetName = "GetVague", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Search for users using a search string from different properties e.g. DisplayName, Job Title, UPN etc.")] [System.String] $SearchString, - [Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Filter to apply to the query.")] [System.String] $Filter, - [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Properties to include in the results.")] [Alias("Select")] [System.String[]] $Property ) diff --git a/module/Entra/Microsoft.Entra/Users/Get-EntraUserAdministrativeUnit.ps1 b/module/Entra/Microsoft.Entra/Users/Get-EntraUserAdministrativeUnit.ps1 index aec18ba8be..a175115d69 100644 --- a/module/Entra/Microsoft.Entra/Users/Get-EntraUserAdministrativeUnit.ps1 +++ b/module/Entra/Microsoft.Entra/Users/Get-EntraUserAdministrativeUnit.ps1 @@ -11,8 +11,16 @@ function Get-EntraUserAdministrativeUnit { [Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Retrieve all user's administrative units.")] [switch] $All, - [Alias('ObjectId')] - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "User object ID or UPN to retrieve.")] + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Specifies the ID of a user (as a UserPrincipalName or ObjectId) in Microsoft Entra ID.")] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserId must be a valid email address or GUID." + })] [System.String] $UserId, [Alias('DirectoryObjectId')] diff --git a/module/Entra/Microsoft.Entra/Users/Get-EntraUserAppRoleAssignment.ps1 b/module/Entra/Microsoft.Entra/Users/Get-EntraUserAppRoleAssignment.ps1 index 84488c49eb..45f02066e0 100644 --- a/module/Entra/Microsoft.Entra/Users/Get-EntraUserAppRoleAssignment.ps1 +++ b/module/Entra/Microsoft.Entra/Users/Get-EntraUserAppRoleAssignment.ps1 @@ -5,18 +5,26 @@ function Get-EntraUserAppRoleAssignment { [CmdletBinding(DefaultParameterSetName = 'GetQuery')] param ( - [Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Maximum number of results to return.")] [Alias("Limit")] [System.Nullable`1[System.Int32]] $Top, - [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Return all items.")] [switch] $All, - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] - [Alias("ObjectId")] + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Specifies the ID of a user (as a UserPrincipalName or ObjectId) in Microsoft Entra ID.")] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserId must be a valid email address or GUID." + })] [System.String] $UserId, - [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Properties to include in the results.")] [Alias("Select")] [System.String[]] $Property ) diff --git a/module/Entra/Microsoft.Entra/Users/Get-EntraUserCreatedObject.ps1 b/module/Entra/Microsoft.Entra/Users/Get-EntraUserCreatedObject.ps1 index 88cdf2ead1..5e4e61491f 100644 --- a/module/Entra/Microsoft.Entra/Users/Get-EntraUserCreatedObject.ps1 +++ b/module/Entra/Microsoft.Entra/Users/Get-EntraUserCreatedObject.ps1 @@ -9,8 +9,16 @@ function Get-EntraUserCreatedObject { [Alias("Limit")] [System.Nullable`1[System.Int32]] $Top, - [Alias('ObjectId')] [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "The unique identifier for the user (User Principal Name or UserId).")] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserId must be a valid email address or GUID." + })] [System.String] $UserId, [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Return all items.")] diff --git a/module/Entra/Microsoft.Entra/Users/Get-EntraUserDirectReport.ps1 b/module/Entra/Microsoft.Entra/Users/Get-EntraUserDirectReport.ps1 index 0b32411fa5..a1a6c39ee0 100644 --- a/module/Entra/Microsoft.Entra/Users/Get-EntraUserDirectReport.ps1 +++ b/module/Entra/Microsoft.Entra/Users/Get-EntraUserDirectReport.ps1 @@ -5,18 +5,26 @@ function Get-EntraUserDirectReport { [CmdletBinding(DefaultParameterSetName = 'GetQuery')] param ( - [Alias('ObjectId')] - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Specifies the ID of a user (as a UserPrincipalName or ObjectId) in Microsoft Entra ID.")] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserId must be a valid email address or GUID." + })] [System.String] $UserId, - [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Return all items.")] [switch] $All, - [Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Maximum number of results to return.")] [Alias("Limit")] [System.Nullable`1[System.Int32]] $Top, - [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Properties to include in the results.")] [Alias("Select")] [System.String[]] $Property ) diff --git a/module/Entra/Microsoft.Entra/Users/Get-EntraUserExtension.ps1 b/module/Entra/Microsoft.Entra/Users/Get-EntraUserExtension.ps1 index 541cb8f672..89ac1556b0 100644 --- a/module/Entra/Microsoft.Entra/Users/Get-EntraUserExtension.ps1 +++ b/module/Entra/Microsoft.Entra/Users/Get-EntraUserExtension.ps1 @@ -5,11 +5,19 @@ function Get-EntraUserExtension { [CmdletBinding(DefaultParameterSetName = 'Default')] param ( - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] - [Alias("ObjectId")] + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Specifies the ID of a user (as a UserPrincipalName or ObjectId) in Microsoft Entra ID.")] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserId must be a valid email address or GUID." + })] [System.String] $UserId, - [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Properties to include in the results.")] [Alias("Select")] [System.String[]] $Property ) diff --git a/module/Entra/Microsoft.Entra/Users/Get-EntraUserGroup.ps1 b/module/Entra/Microsoft.Entra/Users/Get-EntraUserGroup.ps1 index 83a4773b76..88f50c00d7 100644 --- a/module/Entra/Microsoft.Entra/Users/Get-EntraUserGroup.ps1 +++ b/module/Entra/Microsoft.Entra/Users/Get-EntraUserGroup.ps1 @@ -11,8 +11,16 @@ function Get-EntraUserGroup { [Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Retrieve all user's group memberships.")] [switch] $All, - [Alias('ObjectId')] [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "User object ID or UPN to retrieve.")] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserId must be a valid email address or GUID." + })] [System.String] $UserId, [Alias('DirectoryObjectId')] diff --git a/module/Entra/Microsoft.Entra/Users/Get-EntraUserLicenseDetail.ps1 b/module/Entra/Microsoft.Entra/Users/Get-EntraUserLicenseDetail.ps1 index 665982e6ea..26739c1785 100644 --- a/module/Entra/Microsoft.Entra/Users/Get-EntraUserLicenseDetail.ps1 +++ b/module/Entra/Microsoft.Entra/Users/Get-EntraUserLicenseDetail.ps1 @@ -5,12 +5,20 @@ function Get-EntraUserLicenseDetail { [CmdletBinding(DefaultParameterSetName = 'Default')] - param ( - [Alias('ObjectId')] - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + param ( + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Specifies the ID of a user (as a UserPrincipalName or ObjectId) in Microsoft Entra ID.")] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserId must be a valid email address or GUID." + })] [System.String] $UserId, - [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Properties to include in the results.")] [Alias("Select")] [System.String[]] $Property ) diff --git a/module/Entra/Microsoft.Entra/Users/Get-EntraUserManager.ps1 b/module/Entra/Microsoft.Entra/Users/Get-EntraUserManager.ps1 index 900c4cb978..68a4d587b7 100644 --- a/module/Entra/Microsoft.Entra/Users/Get-EntraUserManager.ps1 +++ b/module/Entra/Microsoft.Entra/Users/Get-EntraUserManager.ps1 @@ -5,11 +5,19 @@ function Get-EntraUserManager { [CmdletBinding(DefaultParameterSetName = 'Default')] param ( - [Alias('ObjectId')] - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Specifies the ID of a user (as a UserPrincipalName or ObjectId) in Microsoft Entra ID.")] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserId must be a valid email address or GUID." + })] [System.String] $UserId, - [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Properties to include in the results.")] [Alias("Select")] [System.String[]] $Property ) diff --git a/module/Entra/Microsoft.Entra/Users/Get-EntraUserMembership.ps1 b/module/Entra/Microsoft.Entra/Users/Get-EntraUserMembership.ps1 index a8a2e7d3a3..0485f9a9a2 100644 --- a/module/Entra/Microsoft.Entra/Users/Get-EntraUserMembership.ps1 +++ b/module/Entra/Microsoft.Entra/Users/Get-EntraUserMembership.ps1 @@ -5,18 +5,26 @@ function Get-EntraUserMembership { [CmdletBinding(DefaultParameterSetName = 'GetQuery')] param ( - [Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Maximum number of results to return.")] [Alias("Limit")] [System.Nullable`1[System.Int32]] $Top, - [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Return all items.")] [switch] $All, - - [Alias('ObjectId')] - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Specifies the ID of a user (as a UserPrincipalName or ObjectId) in Microsoft Entra ID.")] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserId must be a valid email address or GUID." + })] [System.String] $UserId, - [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Properties to include in the results.")] [Alias("Select")] [System.String[]] $Property ) diff --git a/module/Entra/Microsoft.Entra/Users/Get-EntraUserOAuth2PermissionGrant.ps1 b/module/Entra/Microsoft.Entra/Users/Get-EntraUserOAuth2PermissionGrant.ps1 index e390e14646..3174c65aad 100644 --- a/module/Entra/Microsoft.Entra/Users/Get-EntraUserOAuth2PermissionGrant.ps1 +++ b/module/Entra/Microsoft.Entra/Users/Get-EntraUserOAuth2PermissionGrant.ps1 @@ -5,18 +5,26 @@ function Get-EntraUserOAuth2PermissionGrant { [CmdletBinding(DefaultParameterSetName = 'GetQuery')] param ( - [Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Maximum number of results to return.")] [Alias("Limit")] [System.Nullable`1[System.Int32]] $Top, - [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Return all items.")] [switch] $All, - - [Alias('ObjectId')] - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Specifies the ID of a user (as a UserPrincipalName or ObjectId) in Microsoft Entra ID.")] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserId must be a valid email address or GUID." + })] [System.String] $UserId, - [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Properties to include in the results.")] [Alias("Select")] [System.String[]] $Property ) diff --git a/module/Entra/Microsoft.Entra/Users/Get-EntraUserOwnedDevice.ps1 b/module/Entra/Microsoft.Entra/Users/Get-EntraUserOwnedDevice.ps1 index 166392d137..a13b40a3bb 100644 --- a/module/Entra/Microsoft.Entra/Users/Get-EntraUserOwnedDevice.ps1 +++ b/module/Entra/Microsoft.Entra/Users/Get-EntraUserOwnedDevice.ps1 @@ -5,18 +5,26 @@ function Get-EntraUserOwnedDevice { [CmdletBinding(DefaultParameterSetName = 'GetQuery')] param ( - [Alias('ObjectId')] - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Specifies the ID of a user (as a UserPrincipalName or ObjectId) in Microsoft Entra ID.")] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserId must be a valid email address or GUID." + })] [System.String] $UserId, - [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Return all items.")] [switch] $All, - [Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Maximum number of results to return.")] [Alias("Limit")] [System.Nullable`1[System.Int32]] $Top, - [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Properties to include in the results.")] [Alias("Select")] [System.String[]] $Property ) diff --git a/module/Entra/Microsoft.Entra/Users/Get-EntraUserOwnedObject.ps1 b/module/Entra/Microsoft.Entra/Users/Get-EntraUserOwnedObject.ps1 index 1f5a2053a6..55dc9af3c0 100644 --- a/module/Entra/Microsoft.Entra/Users/Get-EntraUserOwnedObject.ps1 +++ b/module/Entra/Microsoft.Entra/Users/Get-EntraUserOwnedObject.ps1 @@ -5,18 +5,26 @@ function Get-EntraUserOwnedObject { [CmdletBinding(DefaultParameterSetName = 'GetQuery')] param ( - [Alias('ObjectId')] - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Specifies the ID of a user (as a UserPrincipalName or ObjectId) in Microsoft Entra ID.")] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserId must be a valid email address or GUID." + })] [System.String] $UserId, - [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Return all items.")] [switch] $All, - [Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Maximum number of results to return.")] [Alias("Limit")] [System.Nullable`1[System.Int32]] $Top, - [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Properties to include in the results.")] [Alias("Select")] [System.String[]] $Property ) diff --git a/module/Entra/Microsoft.Entra/Users/Get-EntraUserRegisteredDevice.ps1 b/module/Entra/Microsoft.Entra/Users/Get-EntraUserRegisteredDevice.ps1 index aca08a2fcc..578e9c1ce5 100644 --- a/module/Entra/Microsoft.Entra/Users/Get-EntraUserRegisteredDevice.ps1 +++ b/module/Entra/Microsoft.Entra/Users/Get-EntraUserRegisteredDevice.ps1 @@ -5,8 +5,16 @@ function Get-EntraUserRegisteredDevice { [CmdletBinding(DefaultParameterSetName = 'GetQuery')] param ( - [Alias('ObjectId')] [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "The unique identifier for the user (User Principal Name or UserId).")] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserId must be a valid email address or GUID." + })] [System.String] $UserId, [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Return all registered devices.")] diff --git a/module/Entra/Microsoft.Entra/Users/Get-EntraUserRole.ps1 b/module/Entra/Microsoft.Entra/Users/Get-EntraUserRole.ps1 index 593e7edc51..ae5143088b 100644 --- a/module/Entra/Microsoft.Entra/Users/Get-EntraUserRole.ps1 +++ b/module/Entra/Microsoft.Entra/Users/Get-EntraUserRole.ps1 @@ -12,8 +12,16 @@ function Get-EntraUserRole { [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Retrieve all user roles.")] [switch] $All, - [Alias('ObjectId')] - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "User object ID to retrieve.")] + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Specifies the ID of a user (as a UserPrincipalName or ObjectId) in Microsoft Entra ID.")] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserId must be a valid email address or GUID." + })] [System.String] $UserId, [Alias('DirectoryObjectId')] diff --git a/module/Entra/Microsoft.Entra/Users/Get-EntraUserSponsor.ps1 b/module/Entra/Microsoft.Entra/Users/Get-EntraUserSponsor.ps1 index 1cbd09d623..b40d5f6fae 100644 --- a/module/Entra/Microsoft.Entra/Users/Get-EntraUserSponsor.ps1 +++ b/module/Entra/Microsoft.Entra/Users/Get-EntraUserSponsor.ps1 @@ -10,6 +10,15 @@ function Get-EntraUserSponsor { [System.String] $Filter, [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "The unique identifier (User ID) of the user whose sponsor information you want to retrieve.")] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserId must be a valid email address or GUID." + })] [System.String] $UserId, [Alias('Limit')] diff --git a/module/Entra/Microsoft.Entra/Users/Get-EntraUserThumbnailPhoto.ps1 b/module/Entra/Microsoft.Entra/Users/Get-EntraUserThumbnailPhoto.ps1 index 36297d177c..4b8b152eb0 100644 --- a/module/Entra/Microsoft.Entra/Users/Get-EntraUserThumbnailPhoto.ps1 +++ b/module/Entra/Microsoft.Entra/Users/Get-EntraUserThumbnailPhoto.ps1 @@ -5,20 +5,28 @@ function Get-EntraUserThumbnailPhoto { [CmdletBinding(DefaultParameterSetName = 'GetQuery')] param ( - [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "File name to save the photo.")] [System.String] $FileName, - [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "File path or location to save the photo.")] [System.String] $FilePath, - - [Alias('ObjectId')] - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Specifies the ID of a user (as a UserPrincipalName or ObjectId) in Microsoft Entra ID.")] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserId must be a valid email address or GUID." + })] [System.String] $UserId, - [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "View photo.")] [System.Boolean] $View, - [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Properties to include in the results.")] [Alias("Select")] [System.String[]] $Property ) diff --git a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaDeletedUser.ps1 b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaDeletedUser.ps1 index 65ed821b73..507197118d 100644 --- a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaDeletedUser.ps1 +++ b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaDeletedUser.ps1 @@ -14,8 +14,16 @@ function Get-EntraBetaDeletedUser { [Parameter(ParameterSetName = "GetVague", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Search string to use for vague queries.")] [System.String] $SearchString, - [Alias('Id')] [Parameter(ParameterSetName = "GetById", Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "ID of the user to retrieve.")] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserId must be a valid email address or GUID." + })] [System.String] $UserId, [Alias('Limit')] diff --git a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUser.ps1 b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUser.ps1 index be8d92d364..1742f2fd5d 100644 --- a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUser.ps1 +++ b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUser.ps1 @@ -6,24 +6,24 @@ function Get-EntraBetaUser { [CmdletBinding(DefaultParameterSetName = 'GetQuery')] param ( - [Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Maximum number of results to return.")] [Alias("Limit")] [System.Nullable`1[System.Int32]] $Top, - [Alias("ObjectId")] - [Parameter(ParameterSetName = "GetById", Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [Parameter(ParameterSetName = "GetById", Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Specifies the ID of a user (as a UserPrincipalName or ObjectId) in Microsoft Entra ID.")] [System.String] $UserId, - [Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Filter to apply to the query.")] [System.String] $Filter, - [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Return all users.")] [switch] $All, - [Parameter(ParameterSetName = "GetVague", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(ParameterSetName = "GetVague", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Search for users using a search string from different properties e.g. DisplayName, Job Title, UPN etc.")] [System.String] $SearchString, - [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Properties to include in the results.")] [Alias("Select")] [System.String[]] $Property ) diff --git a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserAdministrativeUnit.ps1 b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserAdministrativeUnit.ps1 index 794f09c2f7..eac9ddda4e 100644 --- a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserAdministrativeUnit.ps1 +++ b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserAdministrativeUnit.ps1 @@ -12,8 +12,16 @@ function Get-EntraBetaUserAdministrativeUnit { [Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Retrieve all user's administrative units.")] [switch] $All, - [Alias('ObjectId')] - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "User object ID or UPN to retrieve.")] + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Specifies the ID of a user (as a UserPrincipalName or ObjectId) in Microsoft Entra ID.")] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserId must be a valid email address or GUID." + })] [System.String] $UserId, [Alias('DirectoryObjectId')] diff --git a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserAppRoleAssignment.ps1 b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserAppRoleAssignment.ps1 index e91a0b7706..e6f9e73f54 100644 --- a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserAppRoleAssignment.ps1 +++ b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserAppRoleAssignment.ps1 @@ -6,18 +6,26 @@ function Get-EntraBetaUserAppRoleAssignment { [CmdletBinding(DefaultParameterSetName = 'GetQuery')] param ( - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] - [Alias("ObjectId")] + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Specifies the ID of a user (as a UserPrincipalName or ObjectId) in Microsoft Entra ID.")] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserId must be a valid email address or GUID." + })] [System.String] $UserId, - [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Return all user's app role assignments.")] [switch] $All, [Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [Alias("Limit")] [System.Nullable`1[System.Int32]] $Top, - [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Properties to include in the results.")] [Alias("Select")] [System.String[]] $Property ) diff --git a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserCreatedObject.ps1 b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserCreatedObject.ps1 index d470100a8d..d7250e12ba 100644 --- a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserCreatedObject.ps1 +++ b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserCreatedObject.ps1 @@ -9,8 +9,16 @@ function Get-EntraBetaUserCreatedObject { [Alias("Limit")] [System.Nullable`1[System.Int32]] $Top, - [Alias('ObjectId')] [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "The unique identifier for the user (User Principal Name or UserId).")] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserId must be a valid email address or GUID." + })] [System.String] $UserId, [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Return all items.")] diff --git a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserDirectReport.ps1 b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserDirectReport.ps1 index d3ce1c85c9..342cb998cb 100644 --- a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserDirectReport.ps1 +++ b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserDirectReport.ps1 @@ -9,14 +9,22 @@ function Get-EntraBetaUserDirectReport { [Alias("Limit")] [System.Nullable`1[System.Int32]] $Top, - [Alias('ObjectId')] - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Specifies the ID of a user (as a UserPrincipalName or ObjectId) in Microsoft Entra ID.")] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserId must be a valid email address or GUID." + })] [System.String] $UserId, - [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Return all items.")] [switch] $All, - [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Properties to include in the results.")] [Alias("Select")] [System.String[]] $Property ) diff --git a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserExtension.ps1 b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserExtension.ps1 index 10d45a5b82..5982595f37 100644 --- a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserExtension.ps1 +++ b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserExtension.ps1 @@ -5,11 +5,19 @@ function Get-EntraBetaUserExtension { [CmdletBinding(DefaultParameterSetName = 'Default')] param ( - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] - [Alias("ObjectId")] + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Specifies the ID of a user (as a UserPrincipalName or ObjectId) in Microsoft Entra ID.")] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserId must be a valid email address or GUID." + })] [System.String] $UserId, - [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Properties to include in the results.")] [Alias("Select")] [System.String[]] $Property ) diff --git a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserGroup.ps1 b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserGroup.ps1 index 38a3e33643..42ec6deec2 100644 --- a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserGroup.ps1 +++ b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserGroup.ps1 @@ -11,8 +11,16 @@ function Get-EntraBetaUserGroup { [Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Retrieve all user's group memberships.")] [switch] $All, - [Alias('ObjectId')] [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "User object ID or UPN to retrieve.")] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserId must be a valid email address or GUID." + })] [System.String] $UserId, [Alias('DirectoryObjectId')] diff --git a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserLicenseDetail.ps1 b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserLicenseDetail.ps1 index 3ba39dd583..03e35b4938 100644 --- a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserLicenseDetail.ps1 +++ b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserLicenseDetail.ps1 @@ -4,12 +4,20 @@ # ------------------------------------------------------------------------------ function Get-EntraBetaUserLicenseDetail { [CmdletBinding(DefaultParameterSetName = 'GetQuery')] - param ( - [Alias('ObjectId')] - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + param ( + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Specifies the ID of a user (as a UserPrincipalName or ObjectId) in Microsoft Entra ID.")] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserId must be a valid email address or GUID." + })] [System.String] $UserId, - [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Properties to include in the results.")] [Alias("Select")] [System.String[]] $Property ) diff --git a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserManager.ps1 b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserManager.ps1 index d50b560c1d..99d74153e9 100644 --- a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserManager.ps1 +++ b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserManager.ps1 @@ -5,11 +5,19 @@ function Get-EntraBetaUserManager { [CmdletBinding(DefaultParameterSetName = 'GetQuery')] param ( - [ALias('ObjectId')] - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Specifies the ID of a user (as a UserPrincipalName or ObjectId) in Microsoft Entra ID.")] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserId must be a valid email address or GUID." + })] [System.String] $UserId, - [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Properties to include in the results.")] [Alias("Select")] [System.String[]] $Property ) diff --git a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserMembership.ps1 b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserMembership.ps1 index 905749c4a9..971c47f33d 100644 --- a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserMembership.ps1 +++ b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserMembership.ps1 @@ -4,19 +4,27 @@ # ------------------------------------------------------------------------------ function Get-EntraBetaUserMembership { [CmdletBinding(DefaultParameterSetName = 'GetQuery')] - param ( - [Alias('ObjectId')] - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + param ( + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Specifies the ID of a user (as a UserPrincipalName or ObjectId) in Microsoft Entra ID.")] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserId must be a valid email address or GUID." + })] [System.String] $UserId, - [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Return all user's memberships.")] [switch] $All, [Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [Alias("Limit")] [System.Nullable`1[System.Int32]] $Top, - [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Properties to include in the results.")] [Alias("Select")] [System.String[]] $Property ) diff --git a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserOAuth2PermissionGrant.ps1 b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserOAuth2PermissionGrant.ps1 index 1537f73fc7..13c8ac6662 100644 --- a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserOAuth2PermissionGrant.ps1 +++ b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserOAuth2PermissionGrant.ps1 @@ -5,18 +5,26 @@ function Get-EntraBetaUserOAuth2PermissionGrant { [CmdletBinding(DefaultParameterSetName = 'GetQuery')] param ( - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] - [Alias("ObjectId")] + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Specifies the ID of a user (as a UserPrincipalName or ObjectId) in Microsoft Entra ID.")] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserId must be a valid email address or GUID." + })] [System.String] $UserId, - [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Return all items.")] [switch] $All, [Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [Alias("Limit")] [System.Nullable`1[System.Int32]] $Top, - [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Properties to include in the results.")] [Alias("Select")] [System.String[]] $Property ) diff --git a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserOwnedDevice.ps1 b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserOwnedDevice.ps1 index ce77854062..f5804874e0 100644 --- a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserOwnedDevice.ps1 +++ b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserOwnedDevice.ps1 @@ -9,14 +9,22 @@ function Get-EntraBetaUserOwnedDevice { [Alias("Limit")] [System.Nullable`1[System.Int32]] $Top, - [Alias('ObjectId')] - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Specifies the ID of a user (as a UserPrincipalName or ObjectId) in Microsoft Entra ID.")] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserId must be a valid email address or GUID." + })] [System.String] $UserId, - [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Return all user's owned devices.")] [switch] $All, - [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Properties to include in the results.")] [Alias("Select")] [System.String[]] $Property ) diff --git a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserOwnedObject.ps1 b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserOwnedObject.ps1 index 1f108d41ad..eb4f23ea67 100644 --- a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserOwnedObject.ps1 +++ b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserOwnedObject.ps1 @@ -9,14 +9,22 @@ function Get-EntraBetaUserOwnedObject { [Alias("Limit")] [System.Nullable`1[System.Int32]] $Top, - [Alias('ObjectId')] - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Specifies the ID of a user (as a UserPrincipalName or ObjectId) in Microsoft Entra ID.")] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserId must be a valid email address or GUID." + })] [System.String] $UserId, - [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Return all user's owned objects.")] [switch] $All, - [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Properties to include in the results.")] [Alias("Select")] [System.String[]] $Property ) diff --git a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserRegisteredDevice.ps1 b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserRegisteredDevice.ps1 index ea6fc485f9..024e681c8f 100644 --- a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserRegisteredDevice.ps1 +++ b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserRegisteredDevice.ps1 @@ -5,8 +5,16 @@ function Get-EntraBetaUserRegisteredDevice { [CmdletBinding(DefaultParameterSetName = 'GetQuery')] param ( - [Alias('ObjectId')] [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "The unique identifier for the user (User Principal Name or UserId).")] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserId must be a valid email address or GUID." + })] [System.String] $UserId, [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Return all registered devices.")] diff --git a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserRole.ps1 b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserRole.ps1 index b0d75d895a..e49fd14175 100644 --- a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserRole.ps1 +++ b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserRole.ps1 @@ -12,8 +12,16 @@ function Get-EntraBetaUserRole { [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Retrieve all user roles.")] [switch] $All, - [Alias('ObjectId')] - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "User object ID to retrieve.")] + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Specifies the ID of a user (as a UserPrincipalName or ObjectId) in Microsoft Entra ID.")] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserId must be a valid email address or GUID." + })] [System.String] $UserId, [Alias('DirectoryObjectId')] diff --git a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserSponsor.ps1 b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserSponsor.ps1 index 7993ac813c..39a7c216b6 100644 --- a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserSponsor.ps1 +++ b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserSponsor.ps1 @@ -10,6 +10,15 @@ function Get-EntraBetaUserSponsor { [System.String] $Filter, [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "The unique identifier (User ID) of the user whose sponsor information you want to retrieve.")] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserId must be a valid email address or GUID." + })] [System.String] $UserId, [Alias('Limit')] diff --git a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserThumbnailPhoto.ps1 b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserThumbnailPhoto.ps1 index 71c06b23b3..1bc0727178 100644 --- a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserThumbnailPhoto.ps1 +++ b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserThumbnailPhoto.ps1 @@ -6,20 +6,28 @@ function Get-EntraBetaUserThumbnailPhoto { [CmdletBinding(DefaultParameterSetName = 'GetQuery')] param ( - [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "View photo.")] [System.Boolean] $View, - [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "File path or location to save the photo.")] [System.String] $FilePath, - - [Alias('ObjectId')] - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Specifies the ID of a user (as a UserPrincipalName or ObjectId) in Microsoft Entra ID.")] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserId must be a valid email address or GUID." + })] [System.String] $UserId, - [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "File name to save the photo.")] [System.String] $FileName, - [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Properties to include in the results.")] [Alias("Select")] [System.String[]] $Property ) diff --git a/module/docs/entra-powershell-beta/Users/Get-EntraBetaDeletedUser.md b/module/docs/entra-powershell-beta/Users/Get-EntraBetaDeletedUser.md index 9d9deb70e2..4e8e85eed6 100644 --- a/module/docs/entra-powershell-beta/Users/Get-EntraBetaDeletedUser.md +++ b/module/docs/entra-powershell-beta/Users/Get-EntraBetaDeletedUser.md @@ -194,7 +194,7 @@ The ObjectId or User Principal Name of the deleted user to be retrieved. ```yaml Type: System.String Parameter Sets: GetById -Aliases: Id +Aliases: ObjectId, UPN, Identity, UserPrincipalName Required: True Position: Named diff --git a/module/docs/entra-powershell-beta/Users/Get-EntraBetaUser.md b/module/docs/entra-powershell-beta/Users/Get-EntraBetaUser.md index 8c5bfaf8bf..902eb0e89d 100644 --- a/module/docs/entra-powershell-beta/Users/Get-EntraBetaUser.md +++ b/module/docs/entra-powershell-beta/Users/Get-EntraBetaUser.md @@ -474,7 +474,7 @@ Specifies the ID (as a User Principal Name (UPN) or UserId) of a user in Microso ```yaml Type: System.String Parameter Sets: GetById -Aliases: ObjectId +Aliases: ObjectId, UPN, Identity, UserPrincipalName Required: True Position: Named diff --git a/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserAdministrativeUnit.md b/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserAdministrativeUnit.md index e9b55faea0..4df51f9cd2 100644 --- a/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserAdministrativeUnit.md +++ b/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserAdministrativeUnit.md @@ -118,6 +118,22 @@ This cmdlet retrieves a list of administrative units to which a specific user be ## Parameters +### -UserId + +Specifies the ID of a user (as a UserPrincipalName or ObjectId) in Microsoft Entra ID. + +```yaml +Type: System.String +Parameter Sets: GetQuery +Aliases: ObjectId, UPN, Identity, UserPrincipalName + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName, ByValue) +Accept wildcard characters: False +``` + ### -All List all pages. diff --git a/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserAppRoleAssignment.md b/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserAppRoleAssignment.md index d11c2871ad..53ef763234 100644 --- a/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserAppRoleAssignment.md +++ b/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserAppRoleAssignment.md @@ -135,7 +135,7 @@ Specifies the ID of a user (as a UserPrincipalName or ObjectId) in Microsoft Ent ```yaml Type: System.String Parameter Sets: (All) -Aliases: ObjectId +Aliases: ObjectId, UPN, Identity, UserPrincipalName Required: True Position: Named diff --git a/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserCreatedObject.md b/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserCreatedObject.md index 1e5854314e..ce1d0595c0 100644 --- a/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserCreatedObject.md +++ b/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserCreatedObject.md @@ -114,7 +114,7 @@ Specifies the ID (as a UserPrincipalName or UserId) of a user in Microsoft Entra ```yaml Type: System.String Parameter Sets: (All) -Aliases: ObjectId +Aliases: ObjectId, UPN, Identity, UserPrincipalName Required: True Position: Named diff --git a/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserDirectReport.md b/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserDirectReport.md index 5cb56d8a10..a0380b0809 100644 --- a/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserDirectReport.md +++ b/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserDirectReport.md @@ -124,7 +124,7 @@ Specifies the ID of a user's UserPrincipalName or UserId in Microsoft Entra ID. ```yaml Type: System.String Parameter Sets: (All) -Aliases: ObjectId +Aliases: ObjectId, UPN, Identity, UserPrincipalName Required: True Position: Named diff --git a/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserExtension.md b/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserExtension.md index 4e63fceeb8..a35c1d12eb 100644 --- a/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserExtension.md +++ b/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserExtension.md @@ -62,12 +62,12 @@ This example shows how to retrieve the extension attributes for a specified user ### -UserId -Specifies the ID of an object. +Specifies the ID of a user's UserPrincipalName or UserId in Microsoft Entra ID. ```yaml Type: System.String Parameter Sets: (All) -Aliases: ObjectId +Aliases: ObjectId, UPN, Identity, UserPrincipalName Required: True Position: Named diff --git a/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserGroup.md b/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserGroup.md index 53a194a447..3197cdec27 100644 --- a/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserGroup.md +++ b/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserGroup.md @@ -123,6 +123,22 @@ This cmdlet retrieves a list of groups to which a specific user belongs using th ## Parameters +### -UserId + +Specifies the ID of a user's UserPrincipalName or UserId in Microsoft Entra ID. + +```yaml +Type: System.String +Parameter Sets: (All) +Aliases: ObjectId, UPN, Identity, UserPrincipalName + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName, ByValue) +Accept wildcard characters: False +``` + ### -All List all pages. diff --git a/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserLicenseDetail.md b/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserLicenseDetail.md index 286e96442d..d46fa41206 100644 --- a/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserLicenseDetail.md +++ b/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserLicenseDetail.md @@ -66,12 +66,12 @@ This example demonstrates how to retrieve license details for a user from Micros ### -UserId -The object ID of the user for which the license details are retrieved. +The object ID of the user for which the license details are retrieved. Specifies the ID of a user's UserPrincipalName or UserId in Microsoft Entra ID. ```yaml Type: System.String Parameter Sets: (All) -Aliases: ObjectId +Aliases: ObjectId, UPN, Identity, UserPrincipalName Required: True Position: Named diff --git a/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserManager.md b/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserManager.md index a1aad511a7..067a923465 100644 --- a/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserManager.md +++ b/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserManager.md @@ -91,12 +91,12 @@ This example demonstrates how to retrieve users without managers. ### -UserId -The unique identifier of a user in Microsoft Entra ID (User Principal Name or UserId). +Specifies the ID of a user's UserPrincipalName or UserId in Microsoft Entra ID. ```yaml Type: System.String Parameter Sets: (All) -Aliases: ObjectId +Aliases: ObjectId, UPN, Identity, UserPrincipalName Required: True Position: Named diff --git a/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserMembership.md b/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserMembership.md index 2d1b929de5..685e3e14fa 100644 --- a/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserMembership.md +++ b/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserMembership.md @@ -179,7 +179,7 @@ Specifies the ID of a user (as a User Principal Name or ObjectId) in Microsoft E ```yaml Type: System.String Parameter Sets: (All) -Aliases: ObjectId +Aliases: ObjectId, UPN, Identity, UserPrincipalName Required: True Position: Named diff --git a/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserOAuth2PermissionGrant.md b/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserOAuth2PermissionGrant.md index b4f073b682..d14a896765 100644 --- a/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserOAuth2PermissionGrant.md +++ b/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserOAuth2PermissionGrant.md @@ -145,7 +145,7 @@ Specifies the ID (as a User Principal Name or ObjectId) of a user in Microsoft E ```yaml Type: System.String Parameter Sets: (All) -Aliases: ObjectId +Aliases: ObjectId, UPN, Identity, UserPrincipalName Required: True Position: Named diff --git a/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserOwnedDevice.md b/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserOwnedDevice.md index 3eded56324..95ce149be4 100644 --- a/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserOwnedDevice.md +++ b/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserOwnedDevice.md @@ -111,7 +111,7 @@ Specifies the ID of a user (as a User Principal Name or UserId) in Microsoft Ent ```yaml Type: System.String Parameter Sets: (All) -Aliases: ObjectId +Aliases: ObjectId, UPN, Identity, UserPrincipalName Required: True Position: Named diff --git a/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserOwnedObject.md b/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserOwnedObject.md index 865e3c7381..60dcce1ae2 100644 --- a/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserOwnedObject.md +++ b/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserOwnedObject.md @@ -129,7 +129,7 @@ Specifies the ID of a user (as a User Principal Name or UserId) in Microsoft Ent ```yaml Type: System.String Parameter Sets: (All) -Aliases: ObjectId +Aliases: ObjectId, UPN, Identity, UserPrincipalName Required: True Position: Named diff --git a/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserRegisteredDevice.md b/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserRegisteredDevice.md index 880b60ac69..620756b2a2 100644 --- a/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserRegisteredDevice.md +++ b/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserRegisteredDevice.md @@ -181,7 +181,7 @@ Specifies the ID of a user (as a User Principal Name or UserId) in Microsoft Ent ```yaml Type: System.String Parameter Sets: (All) -Aliases: ObjectId +Aliases: ObjectId, UPN, Identity, UserPrincipalName Required: True Position: Named diff --git a/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserRole.md b/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserRole.md index 769a3af0a4..b689da190a 100644 --- a/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserRole.md +++ b/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserRole.md @@ -124,6 +124,22 @@ This cmdlet retrieves the directory roles for a specific user by DirectoryRoleId ## Parameters +### -UserId + +Specifies the ID of a user (as a User Principal Name or UserId) in Microsoft Entra ID. + +```yaml +Type: System.String +Parameter Sets: (All) +Aliases: ObjectId, UPN, Identity, UserPrincipalName + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName, ByValue) +Accept wildcard characters: False +``` + ### -All List all pages. diff --git a/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserSponsor.md b/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserSponsor.md index 391a626191..a7ec13f2d6 100644 --- a/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserSponsor.md +++ b/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserSponsor.md @@ -142,6 +142,7 @@ Specifies the ID (as a UserPrincipalName or UserId) of a user in Microsoft Entra ```yaml Type: System.String Parameter Sets: (All) +Aliases: ObjectId, UPN, Identity, UserPrincipalName Required: True Position: Named diff --git a/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserThumbnailPhoto.md b/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserThumbnailPhoto.md index a1f40afea7..677faaf435 100644 --- a/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserThumbnailPhoto.md +++ b/module/docs/entra-powershell-beta/Users/Get-EntraBetaUserThumbnailPhoto.md @@ -63,7 +63,7 @@ The object ID of the user for which the thumbnail photo is retrieved. ```yaml Type: System.String Parameter Sets: (All) -Aliases: ObjectId +Aliases: ObjectId, UPN, Identity, UserPrincipalName Required: True Position: Named diff --git a/module/docs/entra-powershell-v1.0/Users/Get-EntraDeletedUser.md b/module/docs/entra-powershell-v1.0/Users/Get-EntraDeletedUser.md index a47cd813ea..a8e9821da4 100644 --- a/module/docs/entra-powershell-v1.0/Users/Get-EntraDeletedUser.md +++ b/module/docs/entra-powershell-v1.0/Users/Get-EntraDeletedUser.md @@ -194,7 +194,7 @@ The ObjectId or User Principal Name of the deleted user to be retrieved. ```yaml Type: System.String Parameter Sets: GetById -Aliases: Id +Aliases: ObjectId, UPN, Identity, UserPrincipalName Required: True Position: Named diff --git a/module/docs/entra-powershell-v1.0/Users/Get-EntraUser.md b/module/docs/entra-powershell-v1.0/Users/Get-EntraUser.md index 52abe083fb..a804cee19c 100644 --- a/module/docs/entra-powershell-v1.0/Users/Get-EntraUser.md +++ b/module/docs/entra-powershell-v1.0/Users/Get-EntraUser.md @@ -473,7 +473,7 @@ Specifies the ID (as a User Principal Name (UPN) or UserId) of a user in Microso ```yaml Type: System.String Parameter Sets: GetById -Aliases: ObjectId +Aliases: ObjectId, UPN, Identity, UserPrincipalName Required: True Position: Named diff --git a/module/docs/entra-powershell-v1.0/Users/Get-EntraUserAdministrativeUnit.md b/module/docs/entra-powershell-v1.0/Users/Get-EntraUserAdministrativeUnit.md index 5852577b89..366a634410 100644 --- a/module/docs/entra-powershell-v1.0/Users/Get-EntraUserAdministrativeUnit.md +++ b/module/docs/entra-powershell-v1.0/Users/Get-EntraUserAdministrativeUnit.md @@ -118,6 +118,22 @@ This cmdlet retrieves a list of administrative units to which a specific user be ## Parameters +### -UserId + +Specifies the ID of a user (as a UserPrincipalName or ObjectId) in Microsoft Entra ID. + +```yaml +Type: System.String +Parameter Sets: GetQuery +Aliases: ObjectId, UPN, Identity, UserPrincipalName + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName, ByValue) +Accept wildcard characters: False +``` + ### -All List all pages. diff --git a/module/docs/entra-powershell-v1.0/Users/Get-EntraUserAppRoleAssignment.md b/module/docs/entra-powershell-v1.0/Users/Get-EntraUserAppRoleAssignment.md index 6142ed19c9..c2464326f1 100644 --- a/module/docs/entra-powershell-v1.0/Users/Get-EntraUserAppRoleAssignment.md +++ b/module/docs/entra-powershell-v1.0/Users/Get-EntraUserAppRoleAssignment.md @@ -134,7 +134,7 @@ Specifies the ID of a user (as a UserPrincipalName or ObjectId) in Microsoft Ent ```yaml Type: System.String Parameter Sets: (All) -Aliases: ObjectId +Aliases: ObjectId, UPN, Identity, UserPrincipalName Required: True Position: Named diff --git a/module/docs/entra-powershell-v1.0/Users/Get-EntraUserCreatedObject.md b/module/docs/entra-powershell-v1.0/Users/Get-EntraUserCreatedObject.md index 6b78eec871..3a7658952f 100644 --- a/module/docs/entra-powershell-v1.0/Users/Get-EntraUserCreatedObject.md +++ b/module/docs/entra-powershell-v1.0/Users/Get-EntraUserCreatedObject.md @@ -114,7 +114,7 @@ Specifies the ID (as a UserPrincipalName or UserId) of a user in Microsoft Entra ```yaml Type: System.String Parameter Sets: (All) -Aliases: ObjectId +Aliases: ObjectId, UPN, Identity, UserPrincipalName Required: True Position: Named diff --git a/module/docs/entra-powershell-v1.0/Users/Get-EntraUserDirectReport.md b/module/docs/entra-powershell-v1.0/Users/Get-EntraUserDirectReport.md index ccfdfe180b..9f62e94359 100644 --- a/module/docs/entra-powershell-v1.0/Users/Get-EntraUserDirectReport.md +++ b/module/docs/entra-powershell-v1.0/Users/Get-EntraUserDirectReport.md @@ -123,7 +123,7 @@ Specifies the ID of a user's UserPrincipalName or UserId in Microsoft Entra ID. ```yaml Type: System.String Parameter Sets: (All) -Aliases: ObjectId +Aliases: ObjectId, UPN, Identity, UserPrincipalName Required: True Position: Named diff --git a/module/docs/entra-powershell-v1.0/Users/Get-EntraUserExtension.md b/module/docs/entra-powershell-v1.0/Users/Get-EntraUserExtension.md index 7b9448e608..8f978caad4 100644 --- a/module/docs/entra-powershell-v1.0/Users/Get-EntraUserExtension.md +++ b/module/docs/entra-powershell-v1.0/Users/Get-EntraUserExtension.md @@ -66,7 +66,7 @@ Specifies the ID of an object. ```yaml Type: System.String Parameter Sets: (All) -Aliases: ObjectId +Aliases: ObjectId, UPN, Identity, UserPrincipalName Required: True Position: Named diff --git a/module/docs/entra-powershell-v1.0/Users/Get-EntraUserGroup.md b/module/docs/entra-powershell-v1.0/Users/Get-EntraUserGroup.md index 798170906d..fa2ea97431 100644 --- a/module/docs/entra-powershell-v1.0/Users/Get-EntraUserGroup.md +++ b/module/docs/entra-powershell-v1.0/Users/Get-EntraUserGroup.md @@ -123,6 +123,22 @@ This cmdlet retrieves a list of groups to which a specific user belongs using th ## Parameters +### -UserId + +Specifies the ID of a user's UserPrincipalName or UserId in Microsoft Entra ID. + +```yaml +Type: System.String +Parameter Sets: (All) +Aliases: ObjectId, UPN, Identity, UserPrincipalName + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName, ByValue) +Accept wildcard characters: False +``` + ### -All List all pages. diff --git a/module/docs/entra-powershell-v1.0/Users/Get-EntraUserLicenseDetail.md b/module/docs/entra-powershell-v1.0/Users/Get-EntraUserLicenseDetail.md index fd2ff56581..a663f6e5d7 100644 --- a/module/docs/entra-powershell-v1.0/Users/Get-EntraUserLicenseDetail.md +++ b/module/docs/entra-powershell-v1.0/Users/Get-EntraUserLicenseDetail.md @@ -74,12 +74,12 @@ This example demonstrates how to retrieve license details for a user from Micros ### -UserId -The object ID of the user for which the license details are retrieved. +The object ID of the user for which the license details are retrieved. Specifies the ID of a user's UserPrincipalName or UserId in Microsoft Entra ID. ```yaml Type: System.String Parameter Sets: (All) -Aliases: ObjectId +Aliases: ObjectId, UPN, Identity, UserPrincipalName Required: True Position: Named diff --git a/module/docs/entra-powershell-v1.0/Users/Get-EntraUserManager.md b/module/docs/entra-powershell-v1.0/Users/Get-EntraUserManager.md index 7bd32673a2..5a5fdf9f7b 100644 --- a/module/docs/entra-powershell-v1.0/Users/Get-EntraUserManager.md +++ b/module/docs/entra-powershell-v1.0/Users/Get-EntraUserManager.md @@ -91,12 +91,12 @@ This example demonstrates how to retrieve users without managers. ### -UserId -The unique identifier of a user in Microsoft Entra ID (User Principal Name or UserId). +Specifies the ID of a user's UserPrincipalName or UserId in Microsoft Entra ID. ```yaml Type: System.String Parameter Sets: (All) -Aliases: ObjectId +Aliases: ObjectId, UPN, Identity, UserPrincipalName Required: True Position: Named diff --git a/module/docs/entra-powershell-v1.0/Users/Get-EntraUserMembership.md b/module/docs/entra-powershell-v1.0/Users/Get-EntraUserMembership.md index 1265cdf002..5d989dc58f 100644 --- a/module/docs/entra-powershell-v1.0/Users/Get-EntraUserMembership.md +++ b/module/docs/entra-powershell-v1.0/Users/Get-EntraUserMembership.md @@ -178,7 +178,7 @@ Specifies the ID of a user (as a User Principal Name or ObjectId) in Microsoft E ```yaml Type: System.String Parameter Sets: (All) -Aliases: ObjectId +Aliases: ObjectId, UPN, Identity, UserPrincipalName Required: True Position: Named diff --git a/module/docs/entra-powershell-v1.0/Users/Get-EntraUserOAuth2PermissionGrant.md b/module/docs/entra-powershell-v1.0/Users/Get-EntraUserOAuth2PermissionGrant.md index 48919c71d1..af2e9a1327 100644 --- a/module/docs/entra-powershell-v1.0/Users/Get-EntraUserOAuth2PermissionGrant.md +++ b/module/docs/entra-powershell-v1.0/Users/Get-EntraUserOAuth2PermissionGrant.md @@ -128,7 +128,7 @@ Specifies the ID (as a User Principal Name or ObjectId) of a user in Microsoft E ```yaml Type: System.String Parameter Sets: (All) -Aliases: ObjectId +Aliases: ObjectId, UPN, Identity, UserPrincipalName Required: True Position: Named diff --git a/module/docs/entra-powershell-v1.0/Users/Get-EntraUserOwnedDevice.md b/module/docs/entra-powershell-v1.0/Users/Get-EntraUserOwnedDevice.md index 2e714f9dd9..72c744e9af 100644 --- a/module/docs/entra-powershell-v1.0/Users/Get-EntraUserOwnedDevice.md +++ b/module/docs/entra-powershell-v1.0/Users/Get-EntraUserOwnedDevice.md @@ -111,7 +111,7 @@ Specifies the ID of a user (as a User Principal Name or UserId) in Microsoft Ent ```yaml Type: System.String Parameter Sets: (All) -Aliases: ObjectId +Aliases: ObjectId, UPN, Identity, UserPrincipalName Required: True Position: Named diff --git a/module/docs/entra-powershell-v1.0/Users/Get-EntraUserOwnedObject.md b/module/docs/entra-powershell-v1.0/Users/Get-EntraUserOwnedObject.md index dc3436ea51..bbd466c7f2 100644 --- a/module/docs/entra-powershell-v1.0/Users/Get-EntraUserOwnedObject.md +++ b/module/docs/entra-powershell-v1.0/Users/Get-EntraUserOwnedObject.md @@ -129,7 +129,7 @@ Specifies the ID of a user (as a User Principal Name or UserId) in Microsoft Ent ```yaml Type: System.String Parameter Sets: (All) -Aliases: ObjectId +Aliases: ObjectId, UPN, Identity, UserPrincipalName Required: True Position: Named diff --git a/module/docs/entra-powershell-v1.0/Users/Get-EntraUserRegisteredDevice.md b/module/docs/entra-powershell-v1.0/Users/Get-EntraUserRegisteredDevice.md index b23c11510f..b3b1c123f4 100644 --- a/module/docs/entra-powershell-v1.0/Users/Get-EntraUserRegisteredDevice.md +++ b/module/docs/entra-powershell-v1.0/Users/Get-EntraUserRegisteredDevice.md @@ -180,7 +180,7 @@ Specifies the ID of a user (as a User Principal Name or UserId) in Microsoft Ent ```yaml Type: System.String Parameter Sets: (All) -Aliases: ObjectId +Aliases: ObjectId, UPN, Identity, UserPrincipalName Required: True Position: Named diff --git a/module/docs/entra-powershell-v1.0/Users/Get-EntraUserRole.md b/module/docs/entra-powershell-v1.0/Users/Get-EntraUserRole.md index f5a97d0f28..3b67f8ab1f 100644 --- a/module/docs/entra-powershell-v1.0/Users/Get-EntraUserRole.md +++ b/module/docs/entra-powershell-v1.0/Users/Get-EntraUserRole.md @@ -124,6 +124,22 @@ This cmdlet retrieves the directory roles for a specific user by DirectoryRoleId ## Parameters +### -UserId + +Specifies the ID of a user (as a User Principal Name or UserId) in Microsoft Entra ID. + +```yaml +Type: System.String +Parameter Sets: (All) +Aliases: ObjectId, UPN, Identity, UserPrincipalName + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName, ByValue) +Accept wildcard characters: False +``` + ### -All List all pages. diff --git a/module/docs/entra-powershell-v1.0/Users/Get-EntraUserSponsor.md b/module/docs/entra-powershell-v1.0/Users/Get-EntraUserSponsor.md index c214b80be4..35fb94fe2e 100644 --- a/module/docs/entra-powershell-v1.0/Users/Get-EntraUserSponsor.md +++ b/module/docs/entra-powershell-v1.0/Users/Get-EntraUserSponsor.md @@ -142,6 +142,7 @@ Specifies the ID (as a UserPrincipalName or UserId) of a user in Microsoft Entra ```yaml Type: System.String Parameter Sets: (All) +Aliases: ObjectId, UPN, Identity, UserPrincipalName Required: True Position: Named diff --git a/module/docs/entra-powershell-v1.0/Users/Get-EntraUserThumbnailPhoto.md b/module/docs/entra-powershell-v1.0/Users/Get-EntraUserThumbnailPhoto.md index e4b50d867d..2345f57f53 100644 --- a/module/docs/entra-powershell-v1.0/Users/Get-EntraUserThumbnailPhoto.md +++ b/module/docs/entra-powershell-v1.0/Users/Get-EntraUserThumbnailPhoto.md @@ -63,7 +63,7 @@ The object ID of the user for which the thumbnail photo is retrieved. ```yaml Type: System.String Parameter Sets: (All) -Aliases: ObjectId +Aliases: ObjectId, UPN, Identity, UserPrincipalName Required: True Position: Named From 37d876ee28c4ebc41f16dc8dac7bf58b080eb944 Mon Sep 17 00:00:00 2001 From: Steve Mutungi <132555836+SteveMutungi254@users.noreply.github.com> Date: Tue, 1 Apr 2025 11:10:52 +0300 Subject: [PATCH 2/7] Fixing failing tests --- .../Users/Get-EntraDeletedUser.Tests.ps1 | 4 +- .../Get-EntraUserAppRoleAssignment.Tests.ps1 | 4 -- .../Get-EntraUserCreatedObject.Tests.ps1 | 8 +--- .../Users/Get-EntraUserDirectReport.Tests.ps1 | 39 ++++++++------- .../Users/Get-EntraUserExtension.Tests.ps1 | 23 ++++----- .../Get-EntraUserLicenseDetail.Tests.ps1 | 19 ++++---- .../Users/Get-EntraUserManager.Tests.ps1 | 9 ++-- .../Users/Get-EntraUserMembership.Tests.ps1 | 27 +++++------ ...t-EntraUserOAuth2PermissionGrant.Tests.ps1 | 27 +++++------ .../Users/Get-EntraUserOwnedObject.Tests.ps1 | 16 +++---- .../Users/Get-EntraUserSponsor.Tests.ps1 | 46 +++++++++--------- .../Users/Get-EntraBetaDeletedUser.Tests.ps1 | 4 +- .../Get-EntraBetaUserExtension.Tests.ps1 | 23 ++++----- .../Get-EntraBetaUserLicenseDetail.Tests.ps1 | 19 ++++---- .../Users/Get-EntraBetaUserManager.Tests.ps1 | 39 +++++++-------- .../Get-EntraBetaUserMembership.Tests.ps1 | 47 +++++++++---------- ...et-EntraBetaUserRegisteredDevice.Tests.ps1 | 30 ++++++------ .../Users/Get-EntraBetaUserSponsor.Tests.ps1 | 46 +++++++++--------- 18 files changed, 192 insertions(+), 238 deletions(-) diff --git a/test/Entra/Users/Get-EntraDeletedUser.Tests.ps1 b/test/Entra/Users/Get-EntraDeletedUser.Tests.ps1 index 54d5c191ef..a0746a0927 100644 --- a/test/Entra/Users/Get-EntraDeletedUser.Tests.ps1 +++ b/test/Entra/Users/Get-EntraDeletedUser.Tests.ps1 @@ -43,9 +43,7 @@ Describe "Get-EntraDeletedUser" { It "Should fail when UserId is empty" { { Get-EntraDeletedUser -UserId } | Should -Throw "Missing an argument for parameter 'UserId'*" } - It "Should fail when UserId is invalid" { - { Get-EntraDeletedUser -UserId "" } | Should -Throw "Cannot bind argument to parameter 'UserId' because it is an empty string." - } + It "Should return All deleted users" { $result = Get-EntraDeletedUser -All $result | Should -Not -BeNullOrEmpty diff --git a/test/Entra/Users/Get-EntraUserAppRoleAssignment.Tests.ps1 b/test/Entra/Users/Get-EntraUserAppRoleAssignment.Tests.ps1 index dc1b953f03..9801415289 100644 --- a/test/Entra/Users/Get-EntraUserAppRoleAssignment.Tests.ps1 +++ b/test/Entra/Users/Get-EntraUserAppRoleAssignment.Tests.ps1 @@ -48,10 +48,6 @@ Describe "Get-EntraUserAppRoleAssignment" { Should -Invoke -CommandName Get-MgUserAppRoleAssignment -ModuleName Microsoft.Entra.Users -Times 1 } - It "Should fail when UserId is empty string value" { - { Get-EntraUserAppRoleAssignment -UserId "" } | Should -Throw "Cannot bind argument to parameter 'UserId' because it is an empty string." - } - It "Should fail when UserId is empty" { { Get-EntraUserAppRoleAssignment -UserId } | Should -Throw "Missing an argument for parameter 'UserId'. Specify a parameter of type 'System.String' and try again." } diff --git a/test/Entra/Users/Get-EntraUserCreatedObject.Tests.ps1 b/test/Entra/Users/Get-EntraUserCreatedObject.Tests.ps1 index 2f6fc425c2..a03f5a7023 100644 --- a/test/Entra/Users/Get-EntraUserCreatedObject.Tests.ps1 +++ b/test/Entra/Users/Get-EntraUserCreatedObject.Tests.ps1 @@ -70,10 +70,6 @@ Describe "Get-EntraUserCreatedObject" { Should -Invoke -CommandName Get-MgUserCreatedObject -ModuleName Microsoft.Entra.Users -Times 1 } - It "Should fail when UserId is empty string value" { - { Get-EntraUserCreatedObject -UserId "" } | Should -Throw "Cannot bind argument to parameter 'UserId' because it is an empty string." - } - It "Should fail when UserId is empty" { { Get-EntraUserCreatedObject -UserId } | Should -Throw "Missing an argument for parameter 'UserId'. Specify a parameter of type 'System.String' and try again." } @@ -81,7 +77,7 @@ Describe "Get-EntraUserCreatedObject" { It "Should return all contact" { $result = Get-EntraUserCreatedObject -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -All $result | Should -Not -BeNullOrEmpty - Should -Invoke -CommandName Get-MgUserCreatedObject -ModuleName Microsoft.Entra.Users -Times 1 + Should -Invoke -CommandName Get-MgUserCreatedObject -ModuleName Microsoft.Entra.Users -Times 1 } It "Should fail when All has an argument" { @@ -92,7 +88,7 @@ Describe "Get-EntraUserCreatedObject" { $result = Get-EntraUserCreatedObject -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Top 1 $result | Should -Not -BeNullOrEmpty - Should -Invoke -CommandName Get-MgUserCreatedObject -ModuleName Microsoft.Entra.Users -Times 1 + Should -Invoke -CommandName Get-MgUserCreatedObject -ModuleName Microsoft.Entra.Users -Times 1 } It "Should fail when top is empty" { diff --git a/test/Entra/Users/Get-EntraUserDirectReport.Tests.ps1 b/test/Entra/Users/Get-EntraUserDirectReport.Tests.ps1 index 3ab3292900..749218df9b 100644 --- a/test/Entra/Users/Get-EntraUserDirectReport.Tests.ps1 +++ b/test/Entra/Users/Get-EntraUserDirectReport.Tests.ps1 @@ -11,18 +11,18 @@ BeforeAll { return @{ value = @( @{ - "Id" = "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" - "DisplayName" = "Mock-User" - "OnPremisesImmutableId" = $null - "DeletedDateTime" = $null - "OnPremisesSyncEnabled" = $null - "OnPremisesLastSyncDateTime" = $null - "OnPremisesProvisioningErrors" = @{} - "MobilePhone" = "425-555-0100" - "BusinessPhones" = @("425-555-0100") - "ExternalUserState" = $null - "ExternalUserStateChangeDateTime" = $null - "Parameters" = $args + "Id" = "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" + "DisplayName" = "Mock-User" + "OnPremisesImmutableId" = $null + "DeletedDateTime" = $null + "OnPremisesSyncEnabled" = $null + "OnPremisesLastSyncDateTime" = $null + "OnPremisesProvisioningErrors" = @{} + "MobilePhone" = "425-555-0100" + "BusinessPhones" = @("425-555-0100") + "ExternalUserState" = $null + "ExternalUserStateChangeDateTime" = $null + "Parameters" = $args } ) } @@ -51,11 +51,9 @@ Describe "Get-EntraUserDirectReport" { Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Entra.Users -Times 1 } It "Should fail when UserId is empty" { - { Get-EntraUserDirectReport -UserId } | Should -Throw "Missing an argument for parameter 'UserId'*" - } - It "Should fail when UserId is invalid" { - { Get-EntraUserDirectReport -UserId "" } | Should -Throw "Cannot bind argument to parameter 'UserId' because it is an empty string.*" + { Get-EntraUserDirectReport -UserId } | Should -Throw "Missing an argument for parameter 'UserId'*" } + It "Should return all user direct reports" { $result = Get-EntraUserDirectReport -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -All $result | Should -Not -BeNullOrEmpty @@ -74,7 +72,7 @@ Describe "Get-EntraUserDirectReport" { Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Entra.Users -Times 1 } It "Should fail when top is empty" { - { Get-EntraUserDirectReport -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Top } | Should -Throw "Missing an argument for parameter 'Top'*" + { Get-EntraUserDirectReport -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Top } | Should -Throw "Missing an argument for parameter 'Top'*" } It "Should fail when top is invalid" { { Get-EntraUserDirectReport -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Top xyz } | Should -Throw "Cannot process argument transformation on parameter 'Top'*" @@ -87,7 +85,7 @@ Describe "Get-EntraUserDirectReport" { Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Entra.Users -Times 1 } It "Should fail when Property is empty" { - { Get-EntraUserDirectReport -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Property } | Should -Throw "Missing an argument for parameter 'Property'*" + { Get-EntraUserDirectReport -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Property } | Should -Throw "Missing an argument for parameter 'Property'*" } It "Result should contain Properties" { $result = Get-EntraUserDirectReport -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" @@ -107,7 +105,7 @@ Describe "Get-EntraUserDirectReport" { $result = Get-EntraUserDirectReport -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" $params = Get-Parameters -data $result.Parameters - $para= $params | ConvertTo-json | ConvertFrom-Json + $para = $params | ConvertTo-json | ConvertFrom-Json $para.URI | Should -Match "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" } It "Should contain 'User-Agent' header" { @@ -128,7 +126,8 @@ Describe "Get-EntraUserDirectReport" { try { # Act & Assert: Ensure the function doesn't throw an exception { Get-EntraUserDirectReport -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Debug } | Should -Not -Throw - } finally { + } + finally { # Restore original confirmation preference $DebugPreference = $originalDebugPreference } diff --git a/test/Entra/Users/Get-EntraUserExtension.Tests.ps1 b/test/Entra/Users/Get-EntraUserExtension.Tests.ps1 index ec4c17dae0..a9c5ed4feb 100644 --- a/test/Entra/Users/Get-EntraUserExtension.Tests.ps1 +++ b/test/Entra/Users/Get-EntraUserExtension.Tests.ps1 @@ -6,11 +6,11 @@ BeforeAll { $scriptblock = { return @{ - "employeeId" = $null - "createdDateTime" = $null - "onPremisesDistinguishedName" = $null - "identities" = @("testuser@contoso.com") - "Parameters" = $args + "employeeId" = $null + "createdDateTime" = $null + "onPremisesDistinguishedName" = $null + "identities" = @("testuser@contoso.com") + "Parameters" = $args } } @@ -22,14 +22,14 @@ Describe "Get-EntraUserExtension" { $result = Get-EntraUserExtension -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" $result | Should -Not -BeNullOrEmpty - Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Entra.Users -Times 1 + Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Entra.Users -Times 1 } It "Should execute successfully with Alias" { $result = Get-EntraUserExtension -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" $result | Should -Not -BeNullOrEmpty - Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Entra.Users -Times 1 + Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Entra.Users -Times 1 } It "Should contain 'User-Agent' header" { @@ -43,10 +43,6 @@ Describe "Get-EntraUserExtension" { } } - It "Should fail when UserId is empty string value" { - { Get-EntraUserExtension -UserId "" } | Should -Throw "Cannot bind argument to parameter 'UserId' because it is an empty string." - } - It "Should fail when UserId is empty" { { Get-EntraUserExtension -UserId } | Should -Throw "Missing an argument for parameter 'UserId'. Specify a parameter of type 'System.String' and try again." } @@ -55,7 +51,7 @@ Describe "Get-EntraUserExtension" { $result = Get-EntraUserExtension -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -Property DisplayName $result | Should -Not -BeNullOrEmpty - Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Entra.Users -Times 1 + Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Entra.Users -Times 1 } It "Should fail when Property is empty" { @@ -72,7 +68,8 @@ Describe "Get-EntraUserExtension" { { Get-EntraUserExtension -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -Debug } | Should -Not -Throw - } finally { + } + finally { # Restore original confirmation preference $DebugPreference = $originalDebugPreference } diff --git a/test/Entra/Users/Get-EntraUserLicenseDetail.Tests.ps1 b/test/Entra/Users/Get-EntraUserLicenseDetail.Tests.ps1 index e0c9481cef..0d71f5da95 100644 --- a/test/Entra/Users/Get-EntraUserLicenseDetail.Tests.ps1 +++ b/test/Entra/Users/Get-EntraUserLicenseDetail.Tests.ps1 @@ -11,12 +11,12 @@ BeforeAll { # Write-Host "Mocking Get-EntraUserLicenseDetail with parameters: $($args | ConvertTo-Json -Depth 3)" return @( [PSCustomObject]@{ - Id = "X8Wu1RItQkSNL8zKldQ5DmAn38eBLPdOtXhbU5K1cd8" - ServicePlans = @("COMMON_DEFENDER_PLATFORM_FOR_OFFICE", "Bing_Chat_Enterprise", "MESH_IMMERSIVE_FOR_TEAMS", "PURVIEW_DISCOVERY") - SkuId = "00001111-aaaa-2222-bbbb-3333cccc4444" - SkuPartNumber = "ENTERPRISEPREMIUM" + Id = "X8Wu1RItQkSNL8zKldQ5DmAn38eBLPdOtXhbU5K1cd8" + ServicePlans = @("COMMON_DEFENDER_PLATFORM_FOR_OFFICE", "Bing_Chat_Enterprise", "MESH_IMMERSIVE_FOR_TEAMS", "PURVIEW_DISCOVERY") + SkuId = "00001111-aaaa-2222-bbbb-3333cccc4444" + SkuPartNumber = "ENTERPRISEPREMIUM" AdditionalProperties = @{} - parameters = $args + parameters = $args } ) @@ -50,10 +50,6 @@ Describe "Get-EntraUserLicenseDetail" { should -Invoke -CommandName Get-MgUserLicenseDetail -ModuleName Microsoft.Entra.Users -Times 1 } - It "Should fail when UserId is empty string value" { - { Get-EntraUserLicenseDetail -UserId "" } | Should -Throw "Cannot bind argument to parameter 'UserId' because it is an empty string." - } - It "Should fail when UserId is empty" { { Get-EntraUserLicenseDetail -UserId } | Should -Throw "Missing an argument for parameter 'UserId'. Specify a parameter of type 'System.String' and try again." } @@ -71,7 +67,7 @@ Describe "Get-EntraUserLicenseDetail" { Should -Invoke -CommandName Get-MgUserLicenseDetail -ModuleName Microsoft.Entra.Users -Times 1 } It "Should fail when Property is empty" { - { Get-EntraUserLicenseDetail -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Property } | Should -Throw "Missing an argument for parameter 'Property'*" + { Get-EntraUserLicenseDetail -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Property } | Should -Throw "Missing an argument for parameter 'Property'*" } It "Should contain 'User-Agent' header" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraUserLicenseDetail" @@ -94,7 +90,8 @@ Describe "Get-EntraUserLicenseDetail" { try { # Act & Assert: Ensure the function doesn't throw an exception { Get-EntraUserLicenseDetail -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Debug } | Should -Not -Throw - } finally { + } + finally { # Restore original confirmation preference $DebugPreference = $originalDebugPreference } diff --git a/test/Entra/Users/Get-EntraUserManager.Tests.ps1 b/test/Entra/Users/Get-EntraUserManager.Tests.ps1 index db66707353..bb7d15b6d7 100644 --- a/test/Entra/Users/Get-EntraUserManager.Tests.ps1 +++ b/test/Entra/Users/Get-EntraUserManager.Tests.ps1 @@ -73,10 +73,6 @@ Describe "Get-EntraUserManager" { Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Entra.Users -Times 1 } - It "Should fail when UserId is empty string value" { - { Get-EntraUserManager -UserId "" } | Should -Throw "Cannot bind argument to parameter 'UserId' because it is an empty string." - } - It "Should fail when UserId is empty" { { Get-EntraUserManager -UserId } | Should -Throw "Missing an argument for parameter 'UserId'. Specify a parameter of type 'System.String' and try again." } @@ -110,7 +106,7 @@ Describe "Get-EntraUserManager" { } It "Should fail when Property is empty" { - { Get-EntraUserManager -UserId "00aa00aa-bb11-cc22-dd33-44ee44ee44ee" -Property } | Should -Throw "Missing an argument for parameter 'Property'*" + { Get-EntraUserManager -UserId "00aa00aa-bb11-cc22-dd33-44ee44ee44ee" -Property } | Should -Throw "Missing an argument for parameter 'Property'*" } It "Should execute successfully without throwing an error" { @@ -121,7 +117,8 @@ Describe "Get-EntraUserManager" { try { # Act & Assert: Ensure the function doesn't throw an exception { Get-EntraUserManager -UserId "00aa00aa-bb11-cc22-dd33-44ee44ee44ee" -Debug } | Should -Not -Throw - } finally { + } + finally { # Restore original confirmation preference $DebugPreference = $originalDebugPreference } diff --git a/test/Entra/Users/Get-EntraUserMembership.Tests.ps1 b/test/Entra/Users/Get-EntraUserMembership.Tests.ps1 index b335f89709..2a931ba52a 100644 --- a/test/Entra/Users/Get-EntraUserMembership.Tests.ps1 +++ b/test/Entra/Users/Get-EntraUserMembership.Tests.ps1 @@ -2,7 +2,7 @@ # Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. # ------------------------------------------------------------------------------ BeforeAll { - if((Get-Module -Name Microsoft.Entra.Users) -eq $null){ + if ((Get-Module -Name Microsoft.Entra.Users) -eq $null) { Import-Module Microsoft.Entra.Users } Import-Module (Join-Path $PSScriptRoot "..\..\Common-Functions.ps1") -Force @@ -10,14 +10,14 @@ BeforeAll { $scriptblock = { return @( [PSCustomObject]@{ - "DeletedDateTime" = "" - "Id" = "11bb11bb-cc22-dd33-ee44-55ff55ff55ff" - "AdditionalProperties" = @{ - '@odata.type' = '#microsoft.graph.administrativeUnit' - 'displayName' = "NEW2" - 'description' = "TEST221" + "DeletedDateTime" = "" + "Id" = "11bb11bb-cc22-dd33-ee44-55ff55ff55ff" + "AdditionalProperties" = @{ + '@odata.type' = '#microsoft.graph.administrativeUnit' + 'displayName' = "NEW2" + 'description' = "TEST221" } - "Parameters" = $args + "Parameters" = $args } ) } @@ -44,10 +44,6 @@ Describe "Get-EntraUserMembership" { { Get-EntraUserMembership -UserId } | Should -Throw "Missing an argument for parameter 'UserId'*" } - It "Should fail when UserId is invalid" { - { Get-EntraUserMembership -UserId "" } | Should -Throw "Cannot bind argument to parameter 'UserId' because it is an empty string." - } - It "Should return all user membership" { $result = Get-EntraUserMembership -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -All $result | Should -Not -BeNullOrEmpty @@ -86,7 +82,7 @@ Describe "Get-EntraUserMembership" { } It "Property parameter should work" { - $result = Get-EntraUserMembership -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Property Id + $result = Get-EntraUserMembership -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Property Id $result | Should -Not -BeNullOrEmpty $result.Id | Should -Be "11bb11bb-cc22-dd33-ee44-55ff55ff55ff" @@ -94,7 +90,7 @@ Describe "Get-EntraUserMembership" { } It "Should fail when Property is empty" { - { Get-EntraUserMembership -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Property } | Should -Throw "Missing an argument for parameter 'Property'*" + { Get-EntraUserMembership -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Property } | Should -Throw "Missing an argument for parameter 'Property'*" } It "Should contain 'User-Agent' header" { @@ -119,7 +115,8 @@ Describe "Get-EntraUserMembership" { try { # Act & Assert: Ensure the function doesn't throw an exception { Get-EntraUserMembership -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Debug } | Should -Not -Throw - } finally { + } + finally { # Restore original confirmation preference $DebugPreference = $originalDebugPreference } diff --git a/test/Entra/Users/Get-EntraUserOAuth2PermissionGrant.Tests.ps1 b/test/Entra/Users/Get-EntraUserOAuth2PermissionGrant.Tests.ps1 index 0ba340eacb..18a488dabf 100644 --- a/test/Entra/Users/Get-EntraUserOAuth2PermissionGrant.Tests.ps1 +++ b/test/Entra/Users/Get-EntraUserOAuth2PermissionGrant.Tests.ps1 @@ -2,7 +2,7 @@ # Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. # ------------------------------------------------------------------------------ BeforeAll { - if((Get-Module -Name Microsoft.Entra.Users) -eq $null){ + if ((Get-Module -Name Microsoft.Entra.Users) -eq $null) { Import-Module Microsoft.Entra.Users } Import-Module (Join-Path $PSScriptRoot "..\..\Common-Functions.ps1") -Force @@ -10,14 +10,14 @@ BeforeAll { $scriptblock = { return @( [PSCustomObject]@{ - "ClientId" = "00001111-aaaa-2222-bbbb-3333cccc4444" - "ConsentType" = "Principal" - "Id" = "Aa1Bb2Cc3.-Dd4Ee5Ff6Gg7Hh8Ii9_~Jj0Kk1Ll2" - "PrincipalId" = "aaaaaaaa-bbbb-cccc-1111-222222222222" - "ResourceId" = "bbbbbbbb-cccc-dddd-2222-333333333333" - "Scope" = "User.Read openid profile offline_access" - "AdditionalProperties" = @{} - "Parameters" = $args + "ClientId" = "00001111-aaaa-2222-bbbb-3333cccc4444" + "ConsentType" = "Principal" + "Id" = "Aa1Bb2Cc3.-Dd4Ee5Ff6Gg7Hh8Ii9_~Jj0Kk1Ll2" + "PrincipalId" = "aaaaaaaa-bbbb-cccc-1111-222222222222" + "ResourceId" = "bbbbbbbb-cccc-dddd-2222-333333333333" + "Scope" = "User.Read openid profile offline_access" + "AdditionalProperties" = @{} + "Parameters" = $args } ) } @@ -48,10 +48,6 @@ Describe "Get-EntraUserOAuth2PermissionGrant" { { Get-EntraUserOAuth2PermissionGrant -UserId } | Should -Throw "Missing an argument for parameter 'UserId'*" } - It "Should fail when UserId is invalid" { - { Get-EntraUserOAuth2PermissionGrant -UserId "" } | Should -Throw "Cannot bind argument to parameter 'UserId' because it is an empty string." - } - It "Should return all User OAuth2Permission Grant" { $result = Get-EntraUserOAuth2PermissionGrant -UserId "aaaaaaaa-bbbb-cccc-1111-222222222222" -All $result | Should -Not -BeNullOrEmpty @@ -99,7 +95,7 @@ Describe "Get-EntraUserOAuth2PermissionGrant" { } It "Should fail when Property is empty" { - { Get-EntraUserOAuth2PermissionGrant -UserId "aaaaaaaa-bbbb-cccc-1111-222222222222" -Property } | Should -Throw "Missing an argument for parameter 'Property'*" + { Get-EntraUserOAuth2PermissionGrant -UserId "aaaaaaaa-bbbb-cccc-1111-222222222222" -Property } | Should -Throw "Missing an argument for parameter 'Property'*" } It "Should contain 'User-Agent' header" { @@ -124,7 +120,8 @@ Describe "Get-EntraUserOAuth2PermissionGrant" { try { # Act & Assert: Ensure the function doesn't throw an exception { Get-EntraUserOAuth2PermissionGrant -UserId "aaaaaaaa-bbbb-cccc-1111-222222222222" -Debug } | Should -Not -Throw - } finally { + } + finally { # Restore original confirmation preference $DebugPreference = $originalDebugPreference } diff --git a/test/Entra/Users/Get-EntraUserOwnedObject.Tests.ps1 b/test/Entra/Users/Get-EntraUserOwnedObject.Tests.ps1 index 34fba69210..114bb5080d 100644 --- a/test/Entra/Users/Get-EntraUserOwnedObject.Tests.ps1 +++ b/test/Entra/Users/Get-EntraUserOwnedObject.Tests.ps1 @@ -58,9 +58,6 @@ Describe "Get-EntraUserOwnedObject" { should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Entra.Users -Times 1 } - It "Should fail when UserId is empty string value" { - { Get-EntraUserOwnedObject -UserId "" } | Should -Throw "Cannot bind argument to parameter 'UserId' because it is an empty string." - } It "Should fail when UserId is empty" { { Get-EntraUserOwnedObject -UserId } | Should -Throw "Missing an argument for parameter 'UserId'. Specify a parameter of type 'System.String' and try again." @@ -70,7 +67,7 @@ Describe "Get-EntraUserOwnedObject" { $result = Get-EntraUserOwnedObject -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Top 1 $result | Should -Not -BeNullOrEmpty - Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Entra.Users -Times 1 + Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Entra.Users -Times 1 } It "Should fail when top is empty" { @@ -84,7 +81,7 @@ Describe "Get-EntraUserOwnedObject" { It "Should return all contact" { $result = Get-EntraUserOwnedObject -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -All $result | Should -Not -BeNullOrEmpty - Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Entra.Users -Times 1 + Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Entra.Users -Times 1 } It "Should fail when All has an argument" { @@ -112,7 +109,7 @@ Describe "Get-EntraUserOwnedObject" { } It "Property parameter should work" { - $result = Get-EntraUserOwnedObject -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Property displayName + $result = Get-EntraUserOwnedObject -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Property displayName $result | Should -Not -BeNullOrEmpty $result.displayName | Should -Be "ToGraph_443DEM" @@ -120,7 +117,7 @@ Describe "Get-EntraUserOwnedObject" { } It "Should fail when Property is empty" { - { Get-EntraUserOwnedObject -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Property } | Should -Throw "Missing an argument for parameter 'Property'*" + { Get-EntraUserOwnedObject -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Property } | Should -Throw "Missing an argument for parameter 'Property'*" } It "Should execute successfully without throwing an error" { @@ -130,8 +127,9 @@ Describe "Get-EntraUserOwnedObject" { try { # Act & Assert: Ensure the function doesn't throw an exception - { Get-EntraUserOwnedObject -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Debug } | Should -Not -Throw - } finally { + { Get-EntraUserOwnedObject -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Debug } | Should -Not -Throw + } + finally { # Restore original confirmation preference $DebugPreference = $originalDebugPreference } diff --git a/test/Entra/Users/Get-EntraUserSponsor.Tests.ps1 b/test/Entra/Users/Get-EntraUserSponsor.Tests.ps1 index 9eee06cb4b..093111c349 100644 --- a/test/Entra/Users/Get-EntraUserSponsor.Tests.ps1 +++ b/test/Entra/Users/Get-EntraUserSponsor.Tests.ps1 @@ -2,37 +2,34 @@ # Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. # ------------------------------------------------------------------------------ BeforeAll { - if((Get-Module -Name Microsoft.Entra.Users) -eq $null){ + if ((Get-Module -Name Microsoft.Entra.Users) -eq $null) { Import-Module Microsoft.Entra.Users } Import-Module (Join-Path $PSScriptRoot "..\..\Common-Functions.ps1") -Force $scriptblock = { - return @{ - value = @( - @{ - id = "00aa00aa-bb11-cc22-dd33-44ee44ee44e" - country = "United States" - displayName = "Sara Davis" - mail = "z@microsoft.com" - '@odata.type' = "#microsoft.graph.user" - } - @{ - id = "10aa00aa-bb11-cc22-dd33-44ee44ee44e" - mail = "d@microsoft.com" - '@odata.type' = "#microsoft.graph.group" - } - ) + return @{ + value = @( + @{ + id = "00aa00aa-bb11-cc22-dd33-44ee44ee44e" + country = "United States" + displayName = "Sara Davis" + mail = "z@microsoft.com" + '@odata.type' = "#microsoft.graph.user" + } + @{ + id = "10aa00aa-bb11-cc22-dd33-44ee44ee44e" + mail = "d@microsoft.com" + '@odata.type' = "#microsoft.graph.group" + } + ) + } } -} Mock -CommandName Invoke-GraphRequest -MockWith $scriptblock -ModuleName Microsoft.Entra.Users } Describe "Get-EntraUserSponsor" { Context "Test for Get-EntraUserSponsor" { - It "Should fail when UserId is empty string value" { - { Get-EntraUserSponsor -UserId "" } | Should -Throw "Cannot bind argument to parameter 'UserId' because it is an empty string." - } It "Should fail when UserId is empty" { { Get-EntraUserSponsor -UserId } | Should -Throw "Missing an argument for parameter 'UserId'. Specify a parameter of type 'System.String' and try again." @@ -45,11 +42,11 @@ Describe "Get-EntraUserSponsor" { $result[0].country | should -Be "United States" $result[0].displayName | should -Be "Sara Davis" $result[0].mail | should -Be "z@microsoft.com" - $result[0].'@odata.type'| should -Be "#microsoft.graph.user" + $result[0].'@odata.type' | should -Be "#microsoft.graph.user" $result[1].id | should -Be "10aa00aa-bb11-cc22-dd33-44ee44ee44e" $result[1].mail | should -Be "d@microsoft.com" - $result[1].'@odata.type'| should -Be "#microsoft.graph.group" + $result[1].'@odata.type' | should -Be "#microsoft.graph.group" Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Entra.Users -Times 1 } @@ -57,7 +54,7 @@ Describe "Get-EntraUserSponsor" { $result = Get-EntraUserSponsor -UserId "00aa00aa-bb11-cc22-dd33-44ee44ee44e" -Top 1 $result | Should -Not -BeNullOrEmpty - Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Entra.Users -Times 1 + Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Entra.Users -Times 1 } It "Should fail when top is empty" { @@ -95,7 +92,8 @@ Describe "Get-EntraUserSponsor" { { Get-EntraUserSponsor -UserId "00aa00aa-bb11-cc22-dd33-44ee44ee44e" -Debug } | Should -Not -Throw - } finally { + } + finally { # Restore original confirmation preference $DebugPreference = $originalDebugPreference } diff --git a/test/EntraBeta/Users/Get-EntraBetaDeletedUser.Tests.ps1 b/test/EntraBeta/Users/Get-EntraBetaDeletedUser.Tests.ps1 index b8a7043f68..b22b475b99 100644 --- a/test/EntraBeta/Users/Get-EntraBetaDeletedUser.Tests.ps1 +++ b/test/EntraBeta/Users/Get-EntraBetaDeletedUser.Tests.ps1 @@ -43,9 +43,7 @@ Describe "Get-EntraBetaDeletedUser" { It "Should fail when UserId is empty" { { Get-EntraBetaDeletedUser -UserId } | Should -Throw "Missing an argument for parameter 'UserId'*" } - It "Should fail when UserId is invalid" { - { Get-EntraBetaDeletedUser -UserId "" } | Should -Throw "Cannot bind argument to parameter 'UserId' because it is an empty string." - } + It "Should return All deleted users" { $result = Get-EntraBetaDeletedUser -All $result | Should -Not -BeNullOrEmpty diff --git a/test/EntraBeta/Users/Get-EntraBetaUserExtension.Tests.ps1 b/test/EntraBeta/Users/Get-EntraBetaUserExtension.Tests.ps1 index dee10058a8..996e2bbb34 100644 --- a/test/EntraBeta/Users/Get-EntraBetaUserExtension.Tests.ps1 +++ b/test/EntraBeta/Users/Get-EntraBetaUserExtension.Tests.ps1 @@ -6,11 +6,11 @@ BeforeAll { $scriptblock = { return @{ - "employeeId" = $null - "createdDateTime" = $null - "onPremisesDistinguishedName" = $null - "identities" = @("testuser@contoso.com") - "Parameters" = $args + "employeeId" = $null + "createdDateTime" = $null + "onPremisesDistinguishedName" = $null + "identities" = @("testuser@contoso.com") + "Parameters" = $args } } @@ -22,14 +22,14 @@ Describe "Get-EntraBetaUserExtension" { $result = Get-EntraBetaUserExtension -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" $result | Should -Not -BeNullOrEmpty - Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Entra.Beta.Users -Times 1 + Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Entra.Beta.Users -Times 1 } It "Should execute successfully with Alias" { $result = Get-EntraBetaUserExtension -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" $result | Should -Not -BeNullOrEmpty - Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Entra.Beta.Users -Times 1 + Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Entra.Beta.Users -Times 1 } It "Should contain 'User-Agent' header" { @@ -43,10 +43,6 @@ Describe "Get-EntraBetaUserExtension" { } } - It "Should fail when UserId is empty string value" { - { Get-EntraBetaUserExtension -UserId "" } | Should -Throw "Cannot bind argument to parameter 'UserId' because it is an empty string." - } - It "Should fail when UserId is empty" { { Get-EntraBetaUserExtension -UserId } | Should -Throw "Missing an argument for parameter 'UserId'. Specify a parameter of type 'System.String' and try again." } @@ -55,7 +51,7 @@ Describe "Get-EntraBetaUserExtension" { $result = Get-EntraBetaUserExtension -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -Property DisplayName $result | Should -Not -BeNullOrEmpty - Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Entra.Beta.Users -Times 1 + Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Entra.Beta.Users -Times 1 } It "Should fail when Property is empty" { @@ -72,7 +68,8 @@ Describe "Get-EntraBetaUserExtension" { { Get-EntraBetaUserExtension -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -Debug } | Should -Not -Throw - } finally { + } + finally { # Restore original confirmation preference $DebugPreference = $originalDebugPreference } diff --git a/test/EntraBeta/Users/Get-EntraBetaUserLicenseDetail.Tests.ps1 b/test/EntraBeta/Users/Get-EntraBetaUserLicenseDetail.Tests.ps1 index 39fedea276..757a65e027 100644 --- a/test/EntraBeta/Users/Get-EntraBetaUserLicenseDetail.Tests.ps1 +++ b/test/EntraBeta/Users/Get-EntraBetaUserLicenseDetail.Tests.ps1 @@ -2,7 +2,7 @@ # Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. # ------------------------------------------------------------------------------ BeforeAll { - if((Get-Module -Name Microsoft.Entra.Beta.Users) -eq $null){ + if ((Get-Module -Name Microsoft.Entra.Beta.Users) -eq $null) { Import-Module Microsoft.Entra.Beta.Users } Import-Module (Join-Path $PSScriptRoot "..\..\Common-Functions.ps1") -Force @@ -10,12 +10,12 @@ BeforeAll { $scriptblock = { return @( [PSCustomObject]@{ - Id = "A1bC2dE3fH4iJ5kL6mN7oP8qR9sT0u" - ServicePlans = @("COMMON_DEFENDER_PLATFORM_FOR_OFFICE", "Bing_Chat_Enterprise", "MESH_IMMERSIVE_FOR_TEAMS", "PURVIEW_DISCOVERY") - SkuId = "aaaaaaaa-0b0b-1c1c-2d2d-333333333333" - SkuPartNumber = "ENTERPRISEPREMIUM" + Id = "A1bC2dE3fH4iJ5kL6mN7oP8qR9sT0u" + ServicePlans = @("COMMON_DEFENDER_PLATFORM_FOR_OFFICE", "Bing_Chat_Enterprise", "MESH_IMMERSIVE_FOR_TEAMS", "PURVIEW_DISCOVERY") + SkuId = "aaaaaaaa-0b0b-1c1c-2d2d-333333333333" + SkuPartNumber = "ENTERPRISEPREMIUM" AdditionalProperties = @{} - parameters = $args + parameters = $args } ) } @@ -50,10 +50,6 @@ Describe "Get-EntraBetaUserLicenseDetail" { Should -Invoke -CommandName Get-MgBetaUserLicenseDetail -ModuleName Microsoft.Entra.Beta.Users -Times 1 } - It "Should fail when UserId is empty string" { - { Get-EntraBetaUserLicenseDetail -UserId "" } | Should -Throw "Cannot bind argument to parameter 'UserId' because it is an empty string." - } - It "Should fail when UserId is empty" { { Get-EntraBetaUserLicenseDetail -UserId } | Should -Throw "Missing an argument for parameter 'UserId'. Specify a parameter of type 'System.String' and try again." } @@ -85,7 +81,8 @@ Describe "Get-EntraBetaUserLicenseDetail" { try { # Act & Assert: Ensure the function doesn't throw an exception { Get-EntraBetaUserLicenseDetail -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Debug } | Should -Not -Throw - } finally { + } + finally { # Restore original confirmation preference $DebugPreference = $originalDebugPreference } diff --git a/test/EntraBeta/Users/Get-EntraBetaUserManager.Tests.ps1 b/test/EntraBeta/Users/Get-EntraBetaUserManager.Tests.ps1 index 7c48af1737..2008c670d1 100644 --- a/test/EntraBeta/Users/Get-EntraBetaUserManager.Tests.ps1 +++ b/test/EntraBeta/Users/Get-EntraBetaUserManager.Tests.ps1 @@ -1,5 +1,5 @@ BeforeAll { - if((Get-Module -Name Microsoft.Entra.Beta.Users) -eq $null){ + if ((Get-Module -Name Microsoft.Entra.Beta.Users) -eq $null) { Import-Module Microsoft.Entra.Beta.Users } Import-Module (Join-Path $PSScriptRoot "..\..\Common-Functions.ps1") -Force @@ -46,42 +46,42 @@ BeforeAll { assignedLicenses = @( @{ disabledPlans = @() - skuId = '6a0f6da5-0b87-4190-a6ae-9bb5a2b9546a' + skuId = '6a0f6da5-0b87-4190-a6ae-9bb5a2b9546a' } ) assignedPlans = @( @{ - assignedDateTime = '2023-07-07T14:18:07Z' - capabilityStatus = 'Enabled' - service = 'ProcessSimple' - servicePlanId = 'aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb' + assignedDateTime = '2023-07-07T14:18:07Z' + capabilityStatus = 'Enabled' + service = 'ProcessSimple' + servicePlanId = 'aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb' } ) - authorizationInfo = @{certificateUserIds = @()} - cloudRealtimeCommunicationInfo = @{isSipEnabled = $true} + authorizationInfo = @{certificateUserIds = @() } + cloudRealtimeCommunicationInfo = @{isSipEnabled = $true } deviceKeys = @{} identities = @( @{ - signInType = 'userPrincipalName' - issuer = 'contoso.com' + signInType = 'userPrincipalName' + issuer = 'contoso.com' issuerAssignedId = 'MiriamG@contoso.com' } ) onPremisesExtensionAttributes = @{} onPremisesProvisioningErrors = @{} - onPremisesSipInfo = @{isSipEnabled = $false} + onPremisesSipInfo = @{isSipEnabled = $false } provisionedPlans = @( @{ - capabilityStatus = 'Enabled' - provisioningStatus = 'Success' - service = 'SharePoint' + capabilityStatus = 'Enabled' + provisioningStatus = 'Success' + service = 'SharePoint' } ) serviceProvisioningErrors = @{} AdditionalProperties = @{ test = 'data' } - Parameters = $args + Parameters = $args } ) } @@ -108,11 +108,7 @@ Describe "Get-EntraBetaUserManager" { $result.identities[0].issuerAssignedId | Should -Be "MiriamG@contoso.com" Should -Invoke -CommandName Get-MgBetaUserManager -ModuleName Microsoft.Entra.Beta.Users -Times 1 - } - - It "Should fail when ObjectId is empty" { - { Get-EntraBetaUserManager -UserId "" } | Should -Throw "Cannot bind argument to parameter 'UserId' because it is an empty string." - } + } It "Should fail when invalid parameter is passed" { { Get-EntraBetaUserManager -Power "abc" } | Should -Throw "A parameter cannot be found that matches parameter name 'Power'*" @@ -155,7 +151,8 @@ Describe "Get-EntraBetaUserManager" { try { # Act & Assert: Ensure the function doesn't throw an exception { Get-EntraBetaUserManager -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Debug } | Should -Not -Throw - } finally { + } + finally { # Restore original confirmation preference $DebugPreference = $originalDebugPreference } diff --git a/test/EntraBeta/Users/Get-EntraBetaUserMembership.Tests.ps1 b/test/EntraBeta/Users/Get-EntraBetaUserMembership.Tests.ps1 index f069562eca..ea6bb82f2b 100644 --- a/test/EntraBeta/Users/Get-EntraBetaUserMembership.Tests.ps1 +++ b/test/EntraBeta/Users/Get-EntraBetaUserMembership.Tests.ps1 @@ -2,7 +2,7 @@ # Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. # ------------------------------------------------------------------------------ BeforeAll { - if((Get-Module -Name Microsoft.Entra.Beta.Users) -eq $null){ + if ((Get-Module -Name Microsoft.Entra.Beta.Users) -eq $null) { Import-Module Microsoft.Entra.Beta.Users } Import-Module (Join-Path $PSScriptRoot "..\..\Common-Functions.ps1") -Force @@ -10,19 +10,19 @@ BeforeAll { $scriptblock = { return @( [PSCustomObject]@{ - "Id" = "aaaaaaaa-1111-2222-3333-bbbbbbbbbbbb" - "DeletedDateTime" = $null - "AdditionalProperties" = @{ - "@odata.type" = "#microsoft.graph.group" - "displayName" = "Mock-Membership" - "description" = "MockData" - "organizationId" = "00aa00aa-bb11-cc22-dd33-44ee44ee44ee" - "createdByAppId" = "00001111-aaaa-2222-bbbb-3333cccc4444" - "mailEnabled" = $False - "securityEnabled" = $True - "renewedDateTime" = "2023-10-18T07:21:48Z" - } - "Parameters" = $args + "Id" = "aaaaaaaa-1111-2222-3333-bbbbbbbbbbbb" + "DeletedDateTime" = $null + "AdditionalProperties" = @{ + "@odata.type" = "#microsoft.graph.group" + "displayName" = "Mock-Membership" + "description" = "MockData" + "organizationId" = "00aa00aa-bb11-cc22-dd33-44ee44ee44ee" + "createdByAppId" = "00001111-aaaa-2222-bbbb-3333cccc4444" + "mailEnabled" = $False + "securityEnabled" = $True + "renewedDateTime" = "2023-10-18T07:21:48Z" + } + "Parameters" = $args } ) } @@ -51,18 +51,16 @@ Describe "Get-EntraBetaUserMembership" { Should -Invoke -CommandName Get-MgBetaUserMemberOf -ModuleName Microsoft.Entra.Beta.Users -Times 1 } It "Should fail when UserId is empty" { - { Get-EntraBetaUserMembership -UserId } | Should -Throw "Missing an argument for parameter 'UserId'*" - } - It "Should fail when UserId is invalid" { - { Get-EntraBetaUserMembership -UserId "" } | Should -Throw "Cannot bind argument to parameter 'UserId' because it is an empty string." + { Get-EntraBetaUserMembership -UserId } | Should -Throw "Missing an argument for parameter 'UserId'*" } + It "Should return all user memberships" { $result = Get-EntraBetaUserMembership -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -All $result | Should -Not -BeNullOrEmpty Should -Invoke -CommandName Get-MgBetaUserMemberOf -ModuleName Microsoft.Entra.Beta.Users -Times 1 } - It "Should fail when All is invalid" { + It "Should fail when All is invalid" { { Get-EntraBetaUserMembership -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -All xyz } | Should -Throw "A positional parameter cannot be found that accepts argument 'xyz'.*" } It "Should return top 1 user memberships" { @@ -73,9 +71,9 @@ Describe "Get-EntraBetaUserMembership" { Should -Invoke -CommandName Get-MgBetaUserMemberOf -ModuleName Microsoft.Entra.Beta.Users -Times 1 } It "Should fail when Top is empty" { - { Get-EntraBetaUserMembership -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -Top } | Should -Throw "Missing an argument for parameter 'Top'*" + { Get-EntraBetaUserMembership -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -Top } | Should -Throw "Missing an argument for parameter 'Top'*" } - It "Should fail when Top is invalid" { + It "Should fail when Top is invalid" { { Get-EntraBetaUserMembership -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -Top XY } | Should -Throw "Cannot process argument transformation on parameter 'Top'*" } It "Result should Contain ObjectId" { @@ -89,14 +87,14 @@ Describe "Get-EntraBetaUserMembership" { $params.UserId | Should -Be "bbbbbbbb-1111-2222-3333-cccccccccccc" } It "Property parameter should work" { - $result = Get-EntraBetaUserMembership -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -Property Id + $result = Get-EntraBetaUserMembership -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -Property Id $result | Should -Not -BeNullOrEmpty $result.Id | Should -Be 'aaaaaaaa-1111-2222-3333-bbbbbbbbbbbb' Should -Invoke -CommandName Get-MgBetaUserMemberOf -ModuleName Microsoft.Entra.Beta.Users -Times 1 } It "Should fail when Property is empty" { - { Get-EntraBetaUserMembership -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -Property } | Should -Throw "Missing an argument for parameter 'Property'*" + { Get-EntraBetaUserMembership -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -Property } | Should -Throw "Missing an argument for parameter 'Property'*" } It "Should contain 'User-Agent' header" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraBetaUserMembership" @@ -118,7 +116,8 @@ Describe "Get-EntraBetaUserMembership" { try { # Act & Assert: Ensure the function doesn't throw an exception { Get-EntraBetaUserMembership -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -Debug } | Should -Not -Throw - } finally { + } + finally { # Restore original confirmation preference $DebugPreference = $originalDebugPreference } diff --git a/test/EntraBeta/Users/Get-EntraBetaUserRegisteredDevice.Tests.ps1 b/test/EntraBeta/Users/Get-EntraBetaUserRegisteredDevice.Tests.ps1 index 87eca788ca..dcc5b705b8 100644 --- a/test/EntraBeta/Users/Get-EntraBetaUserRegisteredDevice.Tests.ps1 +++ b/test/EntraBeta/Users/Get-EntraBetaUserRegisteredDevice.Tests.ps1 @@ -44,57 +44,55 @@ Describe "Get-EntraBetaUserRegisteredDevice" { $result.AdditionalProperties.deviceId | Should -Be "aaaaaaaa-0b0b-1c1c-2d2d-333333333333" $result.AdditionalProperties.displayName | Should -Be "Mock-App" - Should -Invoke -CommandName Get-MgBetaUserRegisteredDevice -ModuleName Microsoft.Entra.Beta.Users -Times 1 + Should -Invoke -CommandName Get-MgBetaUserRegisteredDevice -ModuleName Microsoft.Entra.Beta.Users -Times 1 } It "Should fail when UserId is empty" { { Get-EntraBetaUserRegisteredDevice -UserId } | Should -Throw "Missing an argument for parameter 'UserId'*" } - It "Should fail when UserId is invalid" { - { Get-EntraBetaUserRegisteredDevice -UserId "" } | Should -Throw "Cannot bind argument to parameter 'UserId' because it is an empty string." - } + It "Should return All user registered devices" { - $result = Get-EntraBetaUserRegisteredDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -All + $result = Get-EntraBetaUserRegisteredDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -All $result | Should -Not -BeNullOrEmpty - Should -Invoke -CommandName Get-MgBetaUserRegisteredDevice -ModuleName Microsoft.Entra.Beta.Users -Times 1 + Should -Invoke -CommandName Get-MgBetaUserRegisteredDevice -ModuleName Microsoft.Entra.Beta.Users -Times 1 } It "Should fail when All is invalid" { - { Get-EntraBetaUserRegisteredDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -All xyz } | Should -Throw "A positional parameter cannot be found that accepts argument 'xyz'.*" + { Get-EntraBetaUserRegisteredDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -All xyz } | Should -Throw "A positional parameter cannot be found that accepts argument 'xyz'.*" } It "Should return top 1 user registered device" { - $result = Get-EntraBetaUserRegisteredDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -Top 1 + $result = Get-EntraBetaUserRegisteredDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -Top 1 $result | Should -Not -BeNullOrEmpty $result.Id | Should -Be "aaaaaaaa-1111-2222-3333-bbbbbbbbbbbb" $result.AdditionalProperties.deviceId | Should -Be "aaaaaaaa-0b0b-1c1c-2d2d-333333333333" $result.AdditionalProperties.displayName | Should -Be "Mock-App" - Should -Invoke -CommandName Get-MgBetaUserRegisteredDevice -ModuleName Microsoft.Entra.Beta.Users -Times 1 + Should -Invoke -CommandName Get-MgBetaUserRegisteredDevice -ModuleName Microsoft.Entra.Beta.Users -Times 1 } It "Should fail when Top is empty" { - { Get-EntraBetaUserRegisteredDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -Top } | Should -Throw "Missing an argument for parameter 'Top'*" + { Get-EntraBetaUserRegisteredDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -Top } | Should -Throw "Missing an argument for parameter 'Top'*" } It "Should fail when Top is invalid" { - { Get-EntraBetaUserRegisteredDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -Top xyz } | Should -Throw "Cannot process argument transformation on parameter 'Top'*" + { Get-EntraBetaUserRegisteredDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -Top xyz } | Should -Throw "Cannot process argument transformation on parameter 'Top'*" } It "Should contain UserId in parameters when passed UserId to it" { - $result = Get-EntraBetaUserRegisteredDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" + $result = Get-EntraBetaUserRegisteredDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" $params = Get-Parameters -data $result.Parameters $params.UserId | Should -Be "bbbbbbbb-1111-2222-3333-cccccccccccc" } It "Property parameter should work" { - $result = Get-EntraBetaUserRegisteredDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -Property Id + $result = Get-EntraBetaUserRegisteredDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -Property Id $result | Should -Not -BeNullOrEmpty $result.Id | Should -Be 'aaaaaaaa-1111-2222-3333-bbbbbbbbbbbb' Should -Invoke -CommandName Get-MgBetaUserRegisteredDevice -ModuleName Microsoft.Entra.Beta.Users -Times 1 } It "Should fail when Property is empty" { - { Get-EntraBetaUserRegisteredDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -Property } | Should -Throw "Missing an argument for parameter 'Property'*" + { Get-EntraBetaUserRegisteredDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -Property } | Should -Throw "Missing an argument for parameter 'Property'*" } It "Should contain 'User-Agent' header" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraBetaUserRegisteredDevice" - $result = Get-EntraBetaUserRegisteredDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" + $result = Get-EntraBetaUserRegisteredDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" $result | Should -Not -BeNullOrEmpty $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraBetaUserRegisteredDevice" @@ -110,7 +108,7 @@ Describe "Get-EntraBetaUserRegisteredDevice" { try { # Act & Assert: Ensure the function doesn't throw an exception - { Get-EntraBetaUserRegisteredDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -Debug } | Should -Not -Throw + { Get-EntraBetaUserRegisteredDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -Debug } | Should -Not -Throw } finally { # Restore original confirmation preference diff --git a/test/EntraBeta/Users/Get-EntraBetaUserSponsor.Tests.ps1 b/test/EntraBeta/Users/Get-EntraBetaUserSponsor.Tests.ps1 index 77ec41cf39..45de294168 100644 --- a/test/EntraBeta/Users/Get-EntraBetaUserSponsor.Tests.ps1 +++ b/test/EntraBeta/Users/Get-EntraBetaUserSponsor.Tests.ps1 @@ -2,37 +2,34 @@ # Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. # ------------------------------------------------------------------------------ BeforeAll { - if((Get-Module -Name Microsoft.Entra.Beta.Users) -eq $null){ + if ((Get-Module -Name Microsoft.Entra.Beta.Users) -eq $null) { Import-Module Microsoft.Entra.Beta.Users } Import-Module (Join-Path $PSScriptRoot "..\..\Common-Functions.ps1") -Force $scriptblock = { - return @{ - value = @( - @{ - id = "00aa00aa-bb11-cc22-dd33-44ee44ee44e" - country = "United States" - displayName = "Sara Davis" - mail = "z@microsoft.com" - '@odata.type' = "#microsoft.graph.user" - } - @{ - id = "10aa00aa-bb11-cc22-dd33-44ee44ee44e" - mail = "d@microsoft.com" - '@odata.type' = "#microsoft.graph.group" - } - ) + return @{ + value = @( + @{ + id = "00aa00aa-bb11-cc22-dd33-44ee44ee44e" + country = "United States" + displayName = "Sara Davis" + mail = "z@microsoft.com" + '@odata.type' = "#microsoft.graph.user" + } + @{ + id = "10aa00aa-bb11-cc22-dd33-44ee44ee44e" + mail = "d@microsoft.com" + '@odata.type' = "#microsoft.graph.group" + } + ) + } } -} Mock -CommandName Invoke-GraphRequest -MockWith $scriptblock -ModuleName Microsoft.Entra.Beta.Users } Describe "Get-EntraBetaUserSponsor" { Context "Test for Get-EntraBetaUserSponsor" { - It "Should fail when UserId is empty string value" { - { Get-EntraBetaUserSponsor -UserId "" } | Should -Throw "Cannot bind argument to parameter 'UserId' because it is an empty string." - } It "Should fail when UserId is empty" { { Get-EntraBetaUserSponsor -UserId } | Should -Throw "Missing an argument for parameter 'UserId'. Specify a parameter of type 'System.String' and try again." @@ -45,11 +42,11 @@ Describe "Get-EntraBetaUserSponsor" { $result[0].country | should -Be "United States" $result[0].displayName | should -Be "Sara Davis" $result[0].mail | should -Be "z@microsoft.com" - $result[0].'@odata.type'| should -Be "#microsoft.graph.user" + $result[0].'@odata.type' | should -Be "#microsoft.graph.user" $result[1].id | should -Be "10aa00aa-bb11-cc22-dd33-44ee44ee44e" $result[1].mail | should -Be "d@microsoft.com" - $result[1].'@odata.type'| should -Be "#microsoft.graph.group" + $result[1].'@odata.type' | should -Be "#microsoft.graph.group" Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Entra.Beta.Users -Times 1 } @@ -57,7 +54,7 @@ Describe "Get-EntraBetaUserSponsor" { $result = Get-EntraBetaUserSponsor -UserId "00aa00aa-bb11-cc22-dd33-44ee44ee44e" -Top 1 $result | Should -Not -BeNullOrEmpty - Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Entra.Beta.Users -Times 1 + Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Entra.Beta.Users -Times 1 } It "Should fail when top is empty" { @@ -95,7 +92,8 @@ Describe "Get-EntraBetaUserSponsor" { { Get-EntraBetaUserSponsor -UserId "00aa00aa-bb11-cc22-dd33-44ee44ee44e" -Debug } | Should -Not -Throw - } finally { + } + finally { # Restore original confirmation preference $DebugPreference = $originalDebugPreference } From f3068f8ffeba1876d5869715cb02ecf960d7cce2 Mon Sep 17 00:00:00 2001 From: Steve Mutungi <132555836+SteveMutungi254@users.noreply.github.com> Date: Tue, 1 Apr 2025 12:43:08 +0300 Subject: [PATCH 3/7] Fix build errors --- .../Users/Get-EntraUserOwnedDevice.Tests.ps1 | 97 +++++++++---------- .../Get-EntraUserRegisteredDevice.Tests.ps1 | 32 +++--- .../Users/Get-EntraUserSponsor.Tests.ps1 | 22 ++--- .../Get-EntraBetaUserOwnedDevice.Tests.ps1 | 71 +++++++------- .../Users/Get-EntraBetaUserSponsor.Tests.ps1 | 20 ++-- 5 files changed, 118 insertions(+), 124 deletions(-) diff --git a/test/Entra/Users/Get-EntraUserOwnedDevice.Tests.ps1 b/test/Entra/Users/Get-EntraUserOwnedDevice.Tests.ps1 index 8b0bd96449..f606961cfa 100644 --- a/test/Entra/Users/Get-EntraUserOwnedDevice.Tests.ps1 +++ b/test/Entra/Users/Get-EntraUserOwnedDevice.Tests.ps1 @@ -2,7 +2,7 @@ # Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. # ------------------------------------------------------------------------------ BeforeAll { - if((Get-Module -Name Microsoft.Entra.Users) -eq $null){ + if ((Get-Module -Name Microsoft.Entra.Users) -eq $null) { Import-Module Microsoft.Entra.Users } Import-Module (Join-Path $PSScriptRoot "..\..\Common-Functions.ps1") -Force @@ -10,35 +10,35 @@ BeforeAll { $scriptblock = { return @( [PSCustomObject]@{ - "Id" = "aaaaaaaa-2222-3333-4444-bbbbbbbbbbbb" - "DeletedDateTime" = $null - "AdditionalProperties" = @{ - "@odata.type" = "#microsoft.graph.device" - "accountEnabled" = $true - "createdDateTime" = "2024-01-18T08:50:28Z" - "deviceId" = "aaaaaaaa-3333-4444-5555-bbbbbbbbbbbb" - "deviceMetadata" = "MetaData" - "deviceVersion" = "2" - "displayName" = "Sawyer Miller" - "isCompliant" = $false - "isManaged" = $true - "operatingSystem" = "WINDOWS" - "operatingSystemVersion" = "10.0.22621.1700" - "physicalIds" = @( - "[HWID]:h:6825786449406074" - "[USER-HWID]:7f08336b-29ed-4297-bb1f-60520d34577f:6825786449406074" - "[GID]:g:6966518641169130" - ) - "systemLabels" = @{} - "extensionAttributes" = $null - "alternativeSecurityIds" = @( - @{ - "type" = 2 - "key" = "dGVzdA==" - } - ) - } - "Parameters" = $args + "Id" = "aaaaaaaa-2222-3333-4444-bbbbbbbbbbbb" + "DeletedDateTime" = $null + "AdditionalProperties" = @{ + "@odata.type" = "#microsoft.graph.device" + "accountEnabled" = $true + "createdDateTime" = "2024-01-18T08:50:28Z" + "deviceId" = "aaaaaaaa-3333-4444-5555-bbbbbbbbbbbb" + "deviceMetadata" = "MetaData" + "deviceVersion" = "2" + "displayName" = "Sawyer Miller" + "isCompliant" = $false + "isManaged" = $true + "operatingSystem" = "WINDOWS" + "operatingSystemVersion" = "10.0.22621.1700" + "physicalIds" = @( + "[HWID]:h:6825786449406074" + "[USER-HWID]:7f08336b-29ed-4297-bb1f-60520d34577f:6825786449406074" + "[GID]:g:6966518641169130" + ) + "systemLabels" = @{} + "extensionAttributes" = $null + "alternativeSecurityIds" = @( + @{ + "type" = 2 + "key" = "dGVzdA==" + } + ) + } + "Parameters" = $args } ) } @@ -46,7 +46,7 @@ BeforeAll { } Describe "Get-EntraUserOwnedDevice" { -Context "Test for Get-EntraUserOwnedDevice" { + Context "Test for Get-EntraUserOwnedDevice" { It "Should get devices owned by a user" { $result = Get-EntraUserOwnedDevice -UserId "aaaaaaaa-1111-2222-3333-bbbbbbbbbbbb" $result | Should -Not -BeNullOrEmpty @@ -54,7 +54,7 @@ Context "Test for Get-EntraUserOwnedDevice" { $result.AdditionalProperties.deviceId | Should -Be "aaaaaaaa-3333-4444-5555-bbbbbbbbbbbb" $result.AdditionalProperties.displayName | Should -Be "Sawyer Miller" - Should -Invoke -CommandName Get-MgUserOwnedDevice -ModuleName Microsoft.Entra.Users -Times 1 + Should -Invoke -CommandName Get-MgUserOwnedDevice -ModuleName Microsoft.Entra.Users -Times 1 } It "Should get devices owned by a user with alias" { @@ -64,7 +64,7 @@ Context "Test for Get-EntraUserOwnedDevice" { $result.AdditionalProperties.deviceId | Should -Be "aaaaaaaa-3333-4444-5555-bbbbbbbbbbbb" $result.AdditionalProperties.displayName | Should -Be "Sawyer Miller" - Should -Invoke -CommandName Get-MgUserOwnedDevice -ModuleName Microsoft.Entra.Users -Times 1 + Should -Invoke -CommandName Get-MgUserOwnedDevice -ModuleName Microsoft.Entra.Users -Times 1 } It "Property parameter should work" { @@ -72,53 +72,49 @@ Context "Test for Get-EntraUserOwnedDevice" { $result.Id | Should -Be 'aaaaaaaa-2222-3333-4444-bbbbbbbbbbbb' } - It "Should fail when ObjectlId is empty" { - { Get-EntraUserOwnedDevice -UserId } | Should -Throw "Missing an argument for parameter 'UserId'*" - } - - It "Should fail when ObjectlId is invalid" { - { Get-EntraUserOwnedDevice -UserId ""} | Should -Throw "Cannot bind argument to parameter 'UserId' because it is an empty string." + It "Should fail when UserId is empty" { + { Get-EntraUserOwnedDevice -UserId } | Should -Throw "Missing an argument for parameter 'UserId'*" } It "Should get all devices owned by a user" { - $result = Get-EntraUserOwnedDevice -UserId "aaaaaaaa-1111-2222-3333-bbbbbbbbbbbb" -All + $result = Get-EntraUserOwnedDevice -UserId "aaaaaaaa-1111-2222-3333-bbbbbbbbbbbb" -All $result | Should -Not -BeNullOrEmpty $result.Id | Should -Contain "aaaaaaaa-2222-3333-4444-bbbbbbbbbbbb" - Should -Invoke -CommandName Get-MgUserOwnedDevice -ModuleName Microsoft.Entra.Users -Times 1 + Should -Invoke -CommandName Get-MgUserOwnedDevice -ModuleName Microsoft.Entra.Users -Times 1 } It "Should fail when All has an argument" { - { Get-EntraGroup -All $true} | Should -Throw "A positional parameter cannot be found that accepts argument 'True'." + { Get-EntraGroup -All $true } | Should -Throw "A positional parameter cannot be found that accepts argument 'True'." } It "Should get top one device owned by a user" { - $result = Get-EntraUserOwnedDevice -UserId "aaaaaaaa-1111-2222-3333-bbbbbbbbbbbb" -Top 1 + $result = Get-EntraUserOwnedDevice -UserId "aaaaaaaa-1111-2222-3333-bbbbbbbbbbbb" -Top 1 $result | Should -Not -BeNullOrEmpty $result.Id | Should -Be "aaaaaaaa-2222-3333-4444-bbbbbbbbbbbb" $result.AdditionalProperties.deviceId | Should -Be "aaaaaaaa-3333-4444-5555-bbbbbbbbbbbb" $result.AdditionalProperties.displayName | Should -Be "Sawyer Miller" - Should -Invoke -CommandName Get-MgUserOwnedDevice -ModuleName Microsoft.Entra.Users -Times 1 + Should -Invoke -CommandName Get-MgUserOwnedDevice -ModuleName Microsoft.Entra.Users -Times 1 } It "Should fail when Top is empty" { - { Get-EntraUserOwnedDevice -UserId "aaaaaaaa-1111-2222-3333-bbbbbbbbbbbb" -Top } | Should -Throw "Missing an argument for parameter 'Top'*" + { Get-EntraUserOwnedDevice -UserId "aaaaaaaa-1111-2222-3333-bbbbbbbbbbbb" -Top } | Should -Throw "Missing an argument for parameter 'Top'*" } It "Should fail when Top is invalid" { - { Get-EntraUserOwnedDevice -UserId "aaaaaaaa-1111-2222-3333-bbbbbbbbbbbb" -Top "XCX" } | Should -Throw "Cannot process argument transformation on parameter 'Top'*" + { Get-EntraUserOwnedDevice -UserId "aaaaaaaa-1111-2222-3333-bbbbbbbbbbbb" -Top "XCX" } | Should -Throw "Cannot process argument transformation on parameter 'Top'*" } It "Should contain UserId in parameters when passed UserId to it" { - $result = Get-EntraUserOwnedDevice -UserId "aaaaaaaa-1111-2222-3333-bbbbbbbbbbbb" + $result = Get-EntraUserOwnedDevice -UserId "aaaaaaaa-1111-2222-3333-bbbbbbbbbbbb" $params = Get-Parameters -data $result.Parameters $params.UserId | Should -Be "aaaaaaaa-1111-2222-3333-bbbbbbbbbbbb" } It "Should contain 'User-Agent' header" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraUserOwnedDevice" - $result = Get-EntraUserOwnedDevice -UserId "aaaaaaaa-1111-2222-3333-bbbbbbbbbbbb" + $result = Get-EntraUserOwnedDevice -UserId "aaaaaaaa-1111-2222-3333-bbbbbbbbbbbb" $result | Should -Not -BeNullOrEmpty $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraUserOwnedDevice" Should -Invoke -CommandName Get-MgUserOwnedDevice -ModuleName Microsoft.Entra.Users -Times 1 -ParameterFilter { @@ -133,8 +129,9 @@ Context "Test for Get-EntraUserOwnedDevice" { try { # Act & Assert: Ensure the function doesn't throw an exception - { Get-EntraUserOwnedDevice -UserId "aaaaaaaa-1111-2222-3333-bbbbbbbbbbbb" -Debug } | Should -Not -Throw - } finally { + { Get-EntraUserOwnedDevice -UserId "aaaaaaaa-1111-2222-3333-bbbbbbbbbbbb" -Debug } | Should -Not -Throw + } + finally { # Restore original confirmation preference $DebugPreference = $originalDebugPreference } diff --git a/test/Entra/Users/Get-EntraUserRegisteredDevice.Tests.ps1 b/test/Entra/Users/Get-EntraUserRegisteredDevice.Tests.ps1 index a9e98d0502..9998c10de3 100644 --- a/test/Entra/Users/Get-EntraUserRegisteredDevice.Tests.ps1 +++ b/test/Entra/Users/Get-EntraUserRegisteredDevice.Tests.ps1 @@ -41,7 +41,7 @@ Describe "Get-EntraUserRegisteredDevice" { $result.AdditionalProperties.deviceId | Should -Be "00001111-aaaa-2222-bbbb-3333cccc4444" $result.AdditionalProperties.displayName | Should -Be "Mock-App" - Should -Invoke -CommandName Get-MgUserRegisteredDevice -ModuleName Microsoft.Entra.Users -Times 1 + Should -Invoke -CommandName Get-MgUserRegisteredDevice -ModuleName Microsoft.Entra.Users -Times 1 } It "Should return specific user registered device with alias" { $result = Get-EntraUserRegisteredDevice -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" @@ -50,59 +50,57 @@ Describe "Get-EntraUserRegisteredDevice" { $result.AdditionalProperties.deviceId | Should -Be "00001111-aaaa-2222-bbbb-3333cccc4444" $result.AdditionalProperties.displayName | Should -Be "Mock-App" - Should -Invoke -CommandName Get-MgUserRegisteredDevice -ModuleName Microsoft.Entra.Users -Times 1 + Should -Invoke -CommandName Get-MgUserRegisteredDevice -ModuleName Microsoft.Entra.Users -Times 1 } It "Should fail when ObjectlId is empty" { { Get-EntraUserRegisteredDevice -UserId } | Should -Throw "Missing an argument for parameter 'UserId'*" } - It "Should fail when ObjectlId is invalid" { - { Get-EntraUserRegisteredDevice -UserId "" } | Should -Throw "Cannot bind argument to parameter 'UserId' because it is an empty string." - } + It "Should return All user registered devices" { - $result = Get-EntraUserRegisteredDevice -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -All + $result = Get-EntraUserRegisteredDevice -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -All $result | Should -Not -BeNullOrEmpty $result.Id | Should -Be "ffffffff-5555-6666-7777-aaaaaaaaaaaa" $result.AdditionalProperties.deviceId | Should -Be "00001111-aaaa-2222-bbbb-3333cccc4444" $result.AdditionalProperties.displayName | Should -Be "Mock-App" - Should -Invoke -CommandName Get-MgUserRegisteredDevice -ModuleName Microsoft.Entra.Users -Times 1 + Should -Invoke -CommandName Get-MgUserRegisteredDevice -ModuleName Microsoft.Entra.Users -Times 1 } It "Should fail when All is invalid" { - { Get-EntraUserRegisteredDevice -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -All xyz } | Should -Throw "A positional parameter cannot be found that accepts argument 'xyz'.*" + { Get-EntraUserRegisteredDevice -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -All xyz } | Should -Throw "A positional parameter cannot be found that accepts argument 'xyz'.*" } It "Should return top 1 user registered device" { - $result = Get-EntraUserRegisteredDevice -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Top 1 + $result = Get-EntraUserRegisteredDevice -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Top 1 $result | Should -Not -BeNullOrEmpty $result.Id | Should -Be "ffffffff-5555-6666-7777-aaaaaaaaaaaa" $result.AdditionalProperties.deviceId | Should -Be "00001111-aaaa-2222-bbbb-3333cccc4444" $result.AdditionalProperties.displayName | Should -Be "Mock-App" - Should -Invoke -CommandName Get-MgUserRegisteredDevice -ModuleName Microsoft.Entra.Users -Times 1 + Should -Invoke -CommandName Get-MgUserRegisteredDevice -ModuleName Microsoft.Entra.Users -Times 1 } It "Should fail when Top is empty" { - { Get-EntraUserRegisteredDevice -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Top } | Should -Throw "Missing an argument for parameter 'Top'*" + { Get-EntraUserRegisteredDevice -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Top } | Should -Throw "Missing an argument for parameter 'Top'*" } It "Should fail when Top is invalid" { - { Get-EntraUserRegisteredDevice -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Top xyz } | Should -Throw "Cannot process argument transformation on parameter 'Top'*" + { Get-EntraUserRegisteredDevice -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Top xyz } | Should -Throw "Cannot process argument transformation on parameter 'Top'*" } It "Property parameter should work" { - $result = Get-EntraUserRegisteredDevice -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Property DisplayName + $result = Get-EntraUserRegisteredDevice -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Property DisplayName $result | Should -Not -BeNullOrEmpty $result.AdditionalProperties.displayName | Should -Be "Mock-App" Should -Invoke -CommandName Get-MgUserRegisteredDevice -ModuleName Microsoft.Entra.Users -Times 1 } It "Should fail when Property is empty" { - { Get-EntraUserRegisteredDevice -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Property } | Should -Throw "Missing an argument for parameter 'Property'*" + { Get-EntraUserRegisteredDevice -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Property } | Should -Throw "Missing an argument for parameter 'Property'*" } It "Should contain UserId in parameters when passed UserId to it" { - $result = Get-EntraUserRegisteredDevice -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" + $result = Get-EntraUserRegisteredDevice -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" $params = Get-Parameters -data $result.Parameters $params.UserId | Should -Be "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" } It "Should contain 'User-Agent' header" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraUserRegisteredDevice" - $result = Get-EntraUserRegisteredDevice -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" + $result = Get-EntraUserRegisteredDevice -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" $result | Should -Not -BeNullOrEmpty $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraUserRegisteredDevice" Should -Invoke -CommandName Get-MgUserRegisteredDevice -ModuleName Microsoft.Entra.Users -Times 1 -ParameterFilter { @@ -117,7 +115,7 @@ Describe "Get-EntraUserRegisteredDevice" { try { # Act & Assert: Ensure the function doesn't throw an exception - { Get-EntraUserRegisteredDevice -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Debug } | Should -Not -Throw + { Get-EntraUserRegisteredDevice -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Debug } | Should -Not -Throw } finally { # Restore original confirmation preference diff --git a/test/Entra/Users/Get-EntraUserSponsor.Tests.ps1 b/test/Entra/Users/Get-EntraUserSponsor.Tests.ps1 index 093111c349..9d03ceac26 100644 --- a/test/Entra/Users/Get-EntraUserSponsor.Tests.ps1 +++ b/test/Entra/Users/Get-EntraUserSponsor.Tests.ps1 @@ -10,14 +10,14 @@ BeforeAll { return @{ value = @( @{ - id = "00aa00aa-bb11-cc22-dd33-44ee44ee44e" + id = "acc9f0a1-9075-464f-9fe7-049bf1ae6481" country = "United States" displayName = "Sara Davis" - mail = "z@microsoft.com" + mail = "sarad@contoso.com" '@odata.type' = "#microsoft.graph.user" } @{ - id = "10aa00aa-bb11-cc22-dd33-44ee44ee44e" + id = "d32766cb-1420-4c0c-986a-d67bedc4014e" mail = "d@microsoft.com" '@odata.type' = "#microsoft.graph.group" } @@ -36,22 +36,22 @@ Describe "Get-EntraUserSponsor" { } It "Should return specific user sponsors" { - $result = Get-EntraUserSponsor -UserId "00aa00aa-bb11-cc22-dd33-44ee44ee44e" + $result = Get-EntraUserSponsor -UserId "acc9f0a1-9075-464f-9fe7-049bf1ae6481" $result | Should -Not -BeNullOrEmpty - $result[0].id | should -Be "00aa00aa-bb11-cc22-dd33-44ee44ee44e" + $result[0].id | should -Be "acc9f0a1-9075-464f-9fe7-049bf1ae6481" $result[0].country | should -Be "United States" $result[0].displayName | should -Be "Sara Davis" - $result[0].mail | should -Be "z@microsoft.com" + $result[0].mail | should -Be "sarad@contoso.com" $result[0].'@odata.type' | should -Be "#microsoft.graph.user" - $result[1].id | should -Be "10aa00aa-bb11-cc22-dd33-44ee44ee44e" + $result[1].id | should -Be "d32766cb-1420-4c0c-986a-d67bedc4014e" $result[1].mail | should -Be "d@microsoft.com" $result[1].'@odata.type' | should -Be "#microsoft.graph.group" Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Entra.Users -Times 1 } It "Should return top user sponsor" { - $result = Get-EntraUserSponsor -UserId "00aa00aa-bb11-cc22-dd33-44ee44ee44e" -Top 1 + $result = Get-EntraUserSponsor -UserId "acc9f0a1-9075-464f-9fe7-049bf1ae6481" -Top 1 $result | Should -Not -BeNullOrEmpty Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Entra.Users -Times 1 @@ -66,7 +66,7 @@ Describe "Get-EntraUserSponsor" { } It 'should handle the Property parameter correctly' { - $UserId = '00aa00aa-bb11-cc22-dd33-44ee44ee44e' + $UserId = 'acc9f0a1-9075-464f-9fe7-049bf1ae6481' $Property = @('id', 'mail') $result = Get-EntraUserSponsor -UserId $UserId -Property $Property $result | Should -Not -BeNullOrEmpty @@ -77,7 +77,7 @@ Describe "Get-EntraUserSponsor" { } It 'should handle the All parameter correctly' { - $UserId = '00aa00aa-bb11-cc22-dd33-44ee44ee44e' + $UserId = 'acc9f0a1-9075-464f-9fe7-049bf1ae6481' $result = Get-EntraUserSponsor -UserId $UserId -All $result | Should -Not -BeNullOrEmpty } @@ -90,7 +90,7 @@ Describe "Get-EntraUserSponsor" { try { # Act & Assert: Ensure the function doesn't throw an exception { - Get-EntraUserSponsor -UserId "00aa00aa-bb11-cc22-dd33-44ee44ee44e" -Debug + Get-EntraUserSponsor -UserId "acc9f0a1-9075-464f-9fe7-049bf1ae6481" -Debug } | Should -Not -Throw } finally { diff --git a/test/EntraBeta/Users/Get-EntraBetaUserOwnedDevice.Tests.ps1 b/test/EntraBeta/Users/Get-EntraBetaUserOwnedDevice.Tests.ps1 index 3bdbdeefed..0e5791dfe9 100644 --- a/test/EntraBeta/Users/Get-EntraBetaUserOwnedDevice.Tests.ps1 +++ b/test/EntraBeta/Users/Get-EntraBetaUserOwnedDevice.Tests.ps1 @@ -2,7 +2,7 @@ # Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. # ------------------------------------------------------------------------------ BeforeAll { - if((Get-Module -Name Microsoft.Entra.Beta.Users) -eq $null){ + if ((Get-Module -Name Microsoft.Entra.Beta.Users) -eq $null) { Import-Module Microsoft.Entra.Beta.Users } Import-Module (Join-Path $PSScriptRoot "..\..\Common-Functions.ps1") -Force @@ -10,24 +10,24 @@ BeforeAll { $scriptblock = { return @( [PSCustomObject]@{ - "Id" = "aaaaaaaa-1111-2222-3333-bbbbbbbbbbbb" - "DeletedDateTime" = $null - "AdditionalProperties" = @{ - "@odata.type" = "#microsoft.graph.device" - "accountEnabled" = $true - "deviceId" = "aaaaaaaa-0b0b-1c1c-2d2d-333333333333" - "createdDateTime" = "2024-01-18T08:50:28Z" - "deviceVersion" = "2" - "displayName" = "Mock-App" - "isCompliant" = $false - "isManaged" = $true - "operatingSystem" = "WINDOWS" - "operatingSystemVersion" = "10.0.22621.1700" - "physicalIds" = "[HWID]:h:6825786449406074" - "systemLabels" = @{} - "extensionAttributes" = $null - } - "Parameters" = $args + "Id" = "aaaaaaaa-1111-2222-3333-bbbbbbbbbbbb" + "DeletedDateTime" = $null + "AdditionalProperties" = @{ + "@odata.type" = "#microsoft.graph.device" + "accountEnabled" = $true + "deviceId" = "aaaaaaaa-0b0b-1c1c-2d2d-333333333333" + "createdDateTime" = "2024-01-18T08:50:28Z" + "deviceVersion" = "2" + "displayName" = "Mock-App" + "isCompliant" = $false + "isManaged" = $true + "operatingSystem" = "WINDOWS" + "operatingSystemVersion" = "10.0.22621.1700" + "physicalIds" = "[HWID]:h:6825786449406074" + "systemLabels" = @{} + "extensionAttributes" = $null + } + "Parameters" = $args } ) } @@ -44,52 +44,50 @@ Describe "Get-EntraBetaUserOwnedDevice" { $result.AdditionalProperties.deviceId | Should -Be "aaaaaaaa-0b0b-1c1c-2d2d-333333333333" $result.AdditionalProperties.displayName | Should -Be "Mock-App" - Should -Invoke -CommandName Get-MgBetaUserOwnedDevice -ModuleName Microsoft.Entra.Beta.Users -Times 1 + Should -Invoke -CommandName Get-MgBetaUserOwnedDevice -ModuleName Microsoft.Entra.Beta.Users -Times 1 } It "Should fail when UserId is empty" { - { Get-EntraBetaUserOwnedDevice -UserId } | Should -Throw "Missing an argument for parameter 'UserId'*" - } - It "Should fail when UserId is invalid" { - { Get-EntraBetaUserOwnedDevice -UserId ""} | Should -Throw "Cannot bind argument to parameter 'UserId' because it is an empty string." + { Get-EntraBetaUserOwnedDevice -UserId } | Should -Throw "Missing an argument for parameter 'UserId'*" } + It "Should return All user registered devices" { - $result = Get-EntraBetaUserOwnedDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -All + $result = Get-EntraBetaUserOwnedDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -All $result | Should -Not -BeNullOrEmpty - Should -Invoke -CommandName Get-MgBetaUserOwnedDevice -ModuleName Microsoft.Entra.Beta.Users -Times 1 + Should -Invoke -CommandName Get-MgBetaUserOwnedDevice -ModuleName Microsoft.Entra.Beta.Users -Times 1 } It "Should fail when All is invalid" { - { Get-EntraBetaUserOwnedDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -All xyz } | Should -Throw "A positional parameter cannot be found that accepts argument 'xyz'.*" + { Get-EntraBetaUserOwnedDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -All xyz } | Should -Throw "A positional parameter cannot be found that accepts argument 'xyz'.*" } It "Should return top 1 user registered device" { - $result = Get-EntraBetaUserOwnedDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -Top 1 + $result = Get-EntraBetaUserOwnedDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -Top 1 $result | Should -Not -BeNullOrEmpty $result.Id | Should -Be "aaaaaaaa-1111-2222-3333-bbbbbbbbbbbb" $result.AdditionalProperties.deviceId | Should -Be "aaaaaaaa-0b0b-1c1c-2d2d-333333333333" $result.AdditionalProperties.displayName | Should -Be "Mock-App" - Should -Invoke -CommandName Get-MgBetaUserOwnedDevice -ModuleName Microsoft.Entra.Beta.Users -Times 1 + Should -Invoke -CommandName Get-MgBetaUserOwnedDevice -ModuleName Microsoft.Entra.Beta.Users -Times 1 } It "Should fail when Top is empty" { - { Get-EntraBetaUserOwnedDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -Top } | Should -Throw "Missing an argument for parameter 'Top'*" + { Get-EntraBetaUserOwnedDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -Top } | Should -Throw "Missing an argument for parameter 'Top'*" } It "Should fail when Top is invalid" { - { Get-EntraBetaUserOwnedDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -Top xyz } | Should -Throw "Cannot process argument transformation on parameter 'Top'*" + { Get-EntraBetaUserOwnedDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -Top xyz } | Should -Throw "Cannot process argument transformation on parameter 'Top'*" } It "Should contain UserId in parameters when passed UserId to it" { - $result = Get-EntraBetaUserOwnedDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" + $result = Get-EntraBetaUserOwnedDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" $params = Get-Parameters -data $result.Parameters $params.UserId | Should -Be "bbbbbbbb-1111-2222-3333-cccccccccccc" } It "Property parameter should work" { - $result = Get-EntraBetaUserOwnedDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -Property Id + $result = Get-EntraBetaUserOwnedDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -Property Id $result | Should -Not -BeNullOrEmpty $result.Id | Should -Be 'aaaaaaaa-1111-2222-3333-bbbbbbbbbbbb' Should -Invoke -CommandName Get-MgBetaUserOwnedDevice -ModuleName Microsoft.Entra.Beta.Users -Times 1 } It "Should fail when Property is empty" { - { Get-EntraBetaUserOwnedDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -Property } | Should -Throw "Missing an argument for parameter 'Property'*" + { Get-EntraBetaUserOwnedDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -Property } | Should -Throw "Missing an argument for parameter 'Property'*" } It "Should contain 'User-Agent' header" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraBetaUserOwnedDevice" @@ -110,8 +108,9 @@ Describe "Get-EntraBetaUserOwnedDevice" { try { # Act & Assert: Ensure the function doesn't throw an exception - { Get-EntraBetaUserOwnedDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -Debug } | Should -Not -Throw - } finally { + { Get-EntraBetaUserOwnedDevice -UserId "bbbbbbbb-1111-2222-3333-cccccccccccc" -Debug } | Should -Not -Throw + } + finally { # Restore original confirmation preference $DebugPreference = $originalDebugPreference } diff --git a/test/EntraBeta/Users/Get-EntraBetaUserSponsor.Tests.ps1 b/test/EntraBeta/Users/Get-EntraBetaUserSponsor.Tests.ps1 index 45de294168..7cf1d691dd 100644 --- a/test/EntraBeta/Users/Get-EntraBetaUserSponsor.Tests.ps1 +++ b/test/EntraBeta/Users/Get-EntraBetaUserSponsor.Tests.ps1 @@ -10,14 +10,14 @@ BeforeAll { return @{ value = @( @{ - id = "00aa00aa-bb11-cc22-dd33-44ee44ee44e" + id = "acc9f0a1-9075-464f-9fe7-049bf1ae6481" country = "United States" displayName = "Sara Davis" - mail = "z@microsoft.com" + mail = "sarad@contoso.com" '@odata.type' = "#microsoft.graph.user" } @{ - id = "10aa00aa-bb11-cc22-dd33-44ee44ee44e" + id = "d32766cb-1420-4c0c-986a-d67bedc4014e" mail = "d@microsoft.com" '@odata.type' = "#microsoft.graph.group" } @@ -36,12 +36,12 @@ Describe "Get-EntraBetaUserSponsor" { } It "Should return specific user sponsors" { - $result = Get-EntraBetaUserSponsor -UserId "00aa00aa-bb11-cc22-dd33-44ee44ee44e" + $result = Get-EntraBetaUserSponsor -UserId "acc9f0a1-9075-464f-9fe7-049bf1ae6481" $result | Should -Not -BeNullOrEmpty - $result[0].id | should -Be "00aa00aa-bb11-cc22-dd33-44ee44ee44e" + $result[0].id | should -Be "acc9f0a1-9075-464f-9fe7-049bf1ae6481" $result[0].country | should -Be "United States" $result[0].displayName | should -Be "Sara Davis" - $result[0].mail | should -Be "z@microsoft.com" + $result[0].mail | should -Be "sarad@contoso.com" $result[0].'@odata.type' | should -Be "#microsoft.graph.user" $result[1].id | should -Be "10aa00aa-bb11-cc22-dd33-44ee44ee44e" @@ -51,7 +51,7 @@ Describe "Get-EntraBetaUserSponsor" { } It "Should return top user sponsor" { - $result = Get-EntraBetaUserSponsor -UserId "00aa00aa-bb11-cc22-dd33-44ee44ee44e" -Top 1 + $result = Get-EntraBetaUserSponsor -UserId "acc9f0a1-9075-464f-9fe7-049bf1ae6481" -Top 1 $result | Should -Not -BeNullOrEmpty Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Entra.Beta.Users -Times 1 @@ -66,7 +66,7 @@ Describe "Get-EntraBetaUserSponsor" { } It 'should handle the Property parameter correctly' { - $UserId = '00aa00aa-bb11-cc22-dd33-44ee44ee44e' + $UserId = 'acc9f0a1-9075-464f-9fe7-049bf1ae6481' $Property = @('id', 'mail') $result = Get-EntraBetaUserSponsor -UserId $UserId -Property $Property $result | Should -Not -BeNullOrEmpty @@ -77,7 +77,7 @@ Describe "Get-EntraBetaUserSponsor" { } It 'should handle the All parameter correctly' { - $UserId = '00aa00aa-bb11-cc22-dd33-44ee44ee44e' + $UserId = 'acc9f0a1-9075-464f-9fe7-049bf1ae6481' $result = Get-EntraBetaUserSponsor -UserId $UserId -All $result | Should -Not -BeNullOrEmpty } @@ -90,7 +90,7 @@ Describe "Get-EntraBetaUserSponsor" { try { # Act & Assert: Ensure the function doesn't throw an exception { - Get-EntraBetaUserSponsor -UserId "00aa00aa-bb11-cc22-dd33-44ee44ee44e" -Debug + Get-EntraBetaUserSponsor -UserId "acc9f0a1-9075-464f-9fe7-049bf1ae6481" -Debug } | Should -Not -Throw } finally { From 6e8d45ad35ae8470f98d32aefab8356175864231 Mon Sep 17 00:00:00 2001 From: Steve Mutungi <132555836+SteveMutungi254@users.noreply.github.com> Date: Tue, 1 Apr 2025 13:35:16 +0300 Subject: [PATCH 4/7] Fix test assertion value --- test/EntraBeta/Users/Get-EntraBetaUserSponsor.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/EntraBeta/Users/Get-EntraBetaUserSponsor.Tests.ps1 b/test/EntraBeta/Users/Get-EntraBetaUserSponsor.Tests.ps1 index 7cf1d691dd..a3bed1a2a6 100644 --- a/test/EntraBeta/Users/Get-EntraBetaUserSponsor.Tests.ps1 +++ b/test/EntraBeta/Users/Get-EntraBetaUserSponsor.Tests.ps1 @@ -44,7 +44,7 @@ Describe "Get-EntraBetaUserSponsor" { $result[0].mail | should -Be "sarad@contoso.com" $result[0].'@odata.type' | should -Be "#microsoft.graph.user" - $result[1].id | should -Be "10aa00aa-bb11-cc22-dd33-44ee44ee44e" + $result[1].id | should -Be "d32766cb-1420-4c0c-986a-d67bedc4014e" $result[1].mail | should -Be "d@microsoft.com" $result[1].'@odata.type' | should -Be "#microsoft.graph.group" Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Entra.Beta.Users -Times 1 From afd9ef7ba71c01d9c7f0cdd4bc13ba967a53cbbf Mon Sep 17 00:00:00 2001 From: Steve Mutungi <132555836+SteveMutungi254@users.noreply.github.com> Date: Tue, 1 Apr 2025 13:41:41 +0300 Subject: [PATCH 5/7] Adding Id alias --- module/Entra/Microsoft.Entra/Users/Get-EntraDeletedUser.ps1 | 2 +- .../Microsoft.Entra.Beta/Users/Get-EntraBetaDeletedUser.ps1 | 2 +- .../entra-powershell-beta/Users/Get-EntraBetaDeletedUser.md | 2 +- module/docs/entra-powershell-v1.0/Users/Get-EntraDeletedUser.md | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/module/Entra/Microsoft.Entra/Users/Get-EntraDeletedUser.ps1 b/module/Entra/Microsoft.Entra/Users/Get-EntraDeletedUser.ps1 index 1fc8c3b2c4..6df6bb2c16 100644 --- a/module/Entra/Microsoft.Entra/Users/Get-EntraDeletedUser.ps1 +++ b/module/Entra/Microsoft.Entra/Users/Get-EntraDeletedUser.ps1 @@ -15,7 +15,7 @@ function Get-EntraDeletedUser { [System.String] $SearchString, [Parameter(ParameterSetName = "GetById", Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "ID of the user to retrieve.")] - [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName', 'Id')] [ValidateNotNullOrEmpty()] [ValidateScript({ if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or diff --git a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaDeletedUser.ps1 b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaDeletedUser.ps1 index 507197118d..d7d82b2617 100644 --- a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaDeletedUser.ps1 +++ b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaDeletedUser.ps1 @@ -15,7 +15,7 @@ function Get-EntraBetaDeletedUser { [System.String] $SearchString, [Parameter(ParameterSetName = "GetById", Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "ID of the user to retrieve.")] - [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')] + [Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName', 'Id')] [ValidateNotNullOrEmpty()] [ValidateScript({ if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or diff --git a/module/docs/entra-powershell-beta/Users/Get-EntraBetaDeletedUser.md b/module/docs/entra-powershell-beta/Users/Get-EntraBetaDeletedUser.md index 4e8e85eed6..c04f292ae4 100644 --- a/module/docs/entra-powershell-beta/Users/Get-EntraBetaDeletedUser.md +++ b/module/docs/entra-powershell-beta/Users/Get-EntraBetaDeletedUser.md @@ -194,7 +194,7 @@ The ObjectId or User Principal Name of the deleted user to be retrieved. ```yaml Type: System.String Parameter Sets: GetById -Aliases: ObjectId, UPN, Identity, UserPrincipalName +Aliases: ObjectId, UPN, Identity, UserPrincipalName, Id Required: True Position: Named diff --git a/module/docs/entra-powershell-v1.0/Users/Get-EntraDeletedUser.md b/module/docs/entra-powershell-v1.0/Users/Get-EntraDeletedUser.md index a8e9821da4..9472477715 100644 --- a/module/docs/entra-powershell-v1.0/Users/Get-EntraDeletedUser.md +++ b/module/docs/entra-powershell-v1.0/Users/Get-EntraDeletedUser.md @@ -194,7 +194,7 @@ The ObjectId or User Principal Name of the deleted user to be retrieved. ```yaml Type: System.String Parameter Sets: GetById -Aliases: ObjectId, UPN, Identity, UserPrincipalName +Aliases: ObjectId, UPN, Identity, UserPrincipalName, Id Required: True Position: Named From 4f91eacdbc4fb86f56b623ff0a09a31222393061 Mon Sep 17 00:00:00 2001 From: Steve Mutungi <132555836+SteveMutungi254@users.noreply.github.com> Date: Tue, 1 Apr 2025 15:14:00 +0300 Subject: [PATCH 6/7] Adding validations for userPrincipalName parameter --- .../Reset-EntraStrongAuthenticationMethodByUpn.ps1 | 7 +++++++ .../Users/Update-EntraUserFromFederated.ps1 | 10 +++++++++- .../Reset-EntraBetaStrongAuthenticationMethodByUpn.ps1 | 7 +++++++ .../Users/Update-EntraBetaUserFromFederated.ps1 | 10 +++++++++- .../Users/Update-EntraBetaUserFromFederated.md | 2 +- .../Users/Update-EntraUserFromFederated.md | 2 +- 6 files changed, 34 insertions(+), 4 deletions(-) diff --git a/module/Entra/Microsoft.Entra/SignIns/Reset-EntraStrongAuthenticationMethodByUpn.ps1 b/module/Entra/Microsoft.Entra/SignIns/Reset-EntraStrongAuthenticationMethodByUpn.ps1 index 6c075f5a85..b12099f632 100644 --- a/module/Entra/Microsoft.Entra/SignIns/Reset-EntraStrongAuthenticationMethodByUpn.ps1 +++ b/module/Entra/Microsoft.Entra/SignIns/Reset-EntraStrongAuthenticationMethodByUpn.ps1 @@ -8,6 +8,13 @@ function Reset-EntraStrongAuthenticationMethodByUpn { [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = 'The unique identifier for the user (User Principal Name or UserId) whose strong authentication method you want to reset.')] [Alias('ObjectId', 'UPN', 'Identity', 'UserId')] [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserPrincipalName must be a valid email address or GUID." + })] [System.String] $UserPrincipalName, [Parameter(ParameterSetName = "ResetAuthenticationMethod", ValueFromPipelineByPropertyName = $true, HelpMessage = 'The tenant ID.')] diff --git a/module/Entra/Microsoft.Entra/Users/Update-EntraUserFromFederated.ps1 b/module/Entra/Microsoft.Entra/Users/Update-EntraUserFromFederated.ps1 index 5bb537cd0b..d2a4c6e9e1 100644 --- a/module/Entra/Microsoft.Entra/Users/Update-EntraUserFromFederated.ps1 +++ b/module/Entra/Microsoft.Entra/Users/Update-EntraUserFromFederated.ps1 @@ -7,7 +7,15 @@ function Update-EntraUserFromFederated { [CmdletBinding(DefaultParameterSetName = 'CloudOnlyPasswordScenarios')] param ( [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "UserPrincipalName of the user to update.")] - [Alias('UserId')] + [Alias('ObjectId', 'UPN', 'Identity', 'UserId')] + [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserPrincipalName must be a valid email address or GUID." + })] [System.String] $UserPrincipalName, [Parameter(ParameterSetName = "HybridPasswordScenarios", Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "New password for the user.")] diff --git a/module/EntraBeta/Microsoft.Entra.Beta/SignIns/Reset-EntraBetaStrongAuthenticationMethodByUpn.ps1 b/module/EntraBeta/Microsoft.Entra.Beta/SignIns/Reset-EntraBetaStrongAuthenticationMethodByUpn.ps1 index a1da29c864..75de3aa7c4 100644 --- a/module/EntraBeta/Microsoft.Entra.Beta/SignIns/Reset-EntraBetaStrongAuthenticationMethodByUpn.ps1 +++ b/module/EntraBeta/Microsoft.Entra.Beta/SignIns/Reset-EntraBetaStrongAuthenticationMethodByUpn.ps1 @@ -8,6 +8,13 @@ function Reset-EntraBetaStrongAuthenticationMethodByUpn { [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = 'The unique identifier for the user (User Principal Name or UserId) whose strong authentication method you want to reset.')] [Alias('ObjectId', 'UPN', 'Identity', 'UserId')] [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserPrincipalName must be a valid email address or GUID." + })] [System.String] $UserPrincipalName, [Parameter(ParameterSetName = "ResetAuthenticationMethod", ValueFromPipelineByPropertyName = $true, HelpMessage = 'The tenant ID.')] diff --git a/module/EntraBeta/Microsoft.Entra.Beta/Users/Update-EntraBetaUserFromFederated.ps1 b/module/EntraBeta/Microsoft.Entra.Beta/Users/Update-EntraBetaUserFromFederated.ps1 index 5c384c7721..9b6c238873 100644 --- a/module/EntraBeta/Microsoft.Entra.Beta/Users/Update-EntraBetaUserFromFederated.ps1 +++ b/module/EntraBeta/Microsoft.Entra.Beta/Users/Update-EntraBetaUserFromFederated.ps1 @@ -7,7 +7,15 @@ function Update-EntraBetaUserFromFederated { [CmdletBinding(DefaultParameterSetName = 'CloudOnlyPasswordScenarios')] param ( [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "UserPrincipalName of the user to update.")] - [Alias('UserId')] + [Alias('ObjectId', 'UPN', 'Identity', 'UserId')] + [ValidateNotNullOrEmpty()] + [ValidateScript({ + if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or + $_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') { + return $true + } + throw "UserPrincipalName must be a valid email address or GUID." + })] [System.String] $UserPrincipalName, [Parameter(ParameterSetName = "HybridPasswordScenarios", Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "New password for the user.")] diff --git a/module/docs/entra-powershell-beta/Users/Update-EntraBetaUserFromFederated.md b/module/docs/entra-powershell-beta/Users/Update-EntraBetaUserFromFederated.md index f502bc1802..e01e669b94 100644 --- a/module/docs/entra-powershell-beta/Users/Update-EntraBetaUserFromFederated.md +++ b/module/docs/entra-powershell-beta/Users/Update-EntraBetaUserFromFederated.md @@ -101,7 +101,7 @@ The Microsoft Entra ID UserID for the user to convert. ```yaml Type: System.String Parameter Sets: (All) -Aliases: UserId +Aliases: UserId, Identity, UPN, ObjectId Required: True Position: 1 diff --git a/module/docs/entra-powershell-v1.0/Users/Update-EntraUserFromFederated.md b/module/docs/entra-powershell-v1.0/Users/Update-EntraUserFromFederated.md index d2e3736b6f..dd56497a97 100644 --- a/module/docs/entra-powershell-v1.0/Users/Update-EntraUserFromFederated.md +++ b/module/docs/entra-powershell-v1.0/Users/Update-EntraUserFromFederated.md @@ -101,7 +101,7 @@ The Microsoft Entra ID UserID for the user to convert. ```yaml Type: System.String Parameter Sets: (All) -Aliases: UserId +Aliases: UserId, Identity, UPN, ObjectId Required: True Position: 1 From e76a1577722f9857d7bf944b735ab2faa0ec69a1 Mon Sep 17 00:00:00 2001 From: Steve Mutungi <132555836+SteveMutungi254@users.noreply.github.com> Date: Tue, 1 Apr 2025 21:51:59 +0300 Subject: [PATCH 7/7] Fix test data to valid values --- ...aStrongAuthenticationMethodByUpn.Tests.ps1 | 20 +++++++++---------- ...aStrongAuthenticationMethodByUpn.Tests.ps1 | 18 ++++++++--------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/test/Entra/SignIns/Reset-EntraStrongAuthenticationMethodByUpn.Tests.ps1 b/test/Entra/SignIns/Reset-EntraStrongAuthenticationMethodByUpn.Tests.ps1 index 4c405a1e00..5b330434f8 100644 --- a/test/Entra/SignIns/Reset-EntraStrongAuthenticationMethodByUpn.Tests.ps1 +++ b/test/Entra/SignIns/Reset-EntraStrongAuthenticationMethodByUpn.Tests.ps1 @@ -9,7 +9,7 @@ BeforeAll { $scriptblock = { return @( [PSCustomObject]@{ - "Id" = "bbbbbbbb-1111-2222-3333-cccccccccccc" + "Id" = "b3f1c54f-1b1f-40fc-8d6d-cd4dc041e959" "AdditionalProperties" = @{ "@odata.type" = "#microsoft.graph.phoneAuthenticationMethod"; createdDateTime = "2023-11-21T12:43:51Z"; @@ -25,7 +25,7 @@ BeforeAll { Describe "Reset-EntraStrongAuthenticationMethodByUpn" { Context "Test for Reset-EntraStrongAuthenticationMethodByUpn" { It "Should Resets the strong authentication method" { - $result = Reset-EntraStrongAuthenticationMethodByUpn -UserPrincipalName 'Test_contoso@M365x99297270.onmicrosoft.com' + $result = Reset-EntraStrongAuthenticationMethodByUpn -UserPrincipalName 'SawyerM@contoso.com' $result | Should -BeNullOrEmpty Should -Invoke -CommandName Get-MgUserAuthenticationMethod -ModuleName Microsoft.Entra.SignIns -Times 1 @@ -35,26 +35,26 @@ Describe "Reset-EntraStrongAuthenticationMethodByUpn" { } It "Should set correct UserId" { - Reset-EntraStrongAuthenticationMethodByUpn -UserPrincipalName 'Test_contoso@M365x99297270.onmicrosoft.com' + Reset-EntraStrongAuthenticationMethodByUpn -UserPrincipalName 'SawyerM@contoso.com' Should -Invoke -CommandName Get-MgUserAuthenticationMethod -ModuleName Microsoft.Entra.SignIns -Times 1 -ParameterFilter { - $userId | Should -Be 'Test_contoso@M365x99297270.onmicrosoft.com' + $userId | Should -Be 'SawyerM@contoso.com' $true } } It "Should set correct PhoneAuthenticationMethodId" { - Reset-EntraStrongAuthenticationMethodByUpn -UserPrincipalName 'Test_contoso@M365x99297270.onmicrosoft.com' + Reset-EntraStrongAuthenticationMethodByUpn -UserPrincipalName 'SawyerM@contoso.com' Should -Invoke -CommandName Get-MgUserAuthenticationMethod -ModuleName Microsoft.Entra.SignIns -Times 1 Should -Invoke -CommandName Remove-MgUserAuthenticationPhoneMethod -ModuleName Microsoft.Entra.SignIns -Times 1 -ParameterFilter { - $userId | Should -Be 'Test_contoso@M365x99297270.onmicrosoft.com' - $PhoneAuthenticationMethodId | Should -Be 'bbbbbbbb-1111-2222-3333-cccccccccccc' + $userId | Should -Be 'SawyerM@contoso.com' + $PhoneAuthenticationMethodId | Should -Be 'b3f1c54f-1b1f-40fc-8d6d-cd4dc041e959' $true } } It "Should contain 'User-Agent' header" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Reset-EntraStrongAuthenticationMethodByUpn" - # Reset-EntraStrongAuthenticationMethodByUpn -UserPrincipalName 'Test_contoso@M365x99297270.onmicrosoft.com' | Out-Null - Reset-EntraStrongAuthenticationMethodByUpn -UserPrincipalName 'Test_contoso@M365x99297270.onmicrosoft.com' + # Reset-EntraStrongAuthenticationMethodByUpn -UserPrincipalName 'SawyerM@contoso.com' | Out-Null + Reset-EntraStrongAuthenticationMethodByUpn -UserPrincipalName 'SawyerM@contoso.com' Should -Invoke -CommandName Get-MgUserAuthenticationMethod -ModuleName Microsoft.Entra.SignIns -Times 1 -ParameterFilter { $Headers.'User-Agent' | Should -Be $userAgentHeaderValue $true @@ -67,7 +67,7 @@ Describe "Reset-EntraStrongAuthenticationMethodByUpn" { try { # Act & Assert: Ensure the function doesn't throw an exception - { Reset-EntraStrongAuthenticationMethodByUpn -UserPrincipalName 'Test_contoso@M365x99297270.onmicrosoft.com' -Debug } | Should -Not -Throw + { Reset-EntraStrongAuthenticationMethodByUpn -UserPrincipalName 'SawyerM@contoso.com' -Debug } | Should -Not -Throw } finally { # Restore original confirmation preference diff --git a/test/EntraBeta/SignIns/Reset-EntraBetaStrongAuthenticationMethodByUpn.Tests.ps1 b/test/EntraBeta/SignIns/Reset-EntraBetaStrongAuthenticationMethodByUpn.Tests.ps1 index 8b42af2f52..c71663ddc6 100644 --- a/test/EntraBeta/SignIns/Reset-EntraBetaStrongAuthenticationMethodByUpn.Tests.ps1 +++ b/test/EntraBeta/SignIns/Reset-EntraBetaStrongAuthenticationMethodByUpn.Tests.ps1 @@ -9,7 +9,7 @@ BeforeAll { $scriptblock = { return @( [PSCustomObject]@{ - "Id" = "bbbbbbbb-1111-2222-3333-cccccccccccc" + "Id" = "b3f1c54f-1b1f-40fc-8d6d-cd4dc041e959" "AdditionalProperties" = @{ "@odata.type" = "#microsoft.graph.phoneAuthenticationMethod"; createdDateTime = "2023-11-21T12:43:51Z"; @@ -25,7 +25,7 @@ BeforeAll { Describe "Reset-EntraBetaStrongAuthenticationMethodByUpn" { Context "Test for Reset-EntraBetaStrongAuthenticationMethodByUpn" { It "Should Resets the strong authentication method" { - $result = Reset-EntraBetaStrongAuthenticationMethodByUpn -UserPrincipalName 'Test_contoso.com#EXT#@M365x99297270.onmicrosoft.com' + $result = Reset-EntraBetaStrongAuthenticationMethodByUpn -UserPrincipalName 'SawyerM@contoso.com' $result | Should -BeNullOrEmpty Should -Invoke -CommandName Get-MgBetaUserAuthenticationMethod -ModuleName Microsoft.Entra.Beta.SignIns -Times 1 @@ -35,25 +35,25 @@ Describe "Reset-EntraBetaStrongAuthenticationMethodByUpn" { } It "Should set correct UserId" { - Reset-EntraBetaStrongAuthenticationMethodByUpn -UserPrincipalName 'Test_contoso@M365x99297270.onmicrosoft.com' + Reset-EntraBetaStrongAuthenticationMethodByUpn -UserPrincipalName 'SawyerM@contoso.com' Should -Invoke -CommandName Get-MgBetaUserAuthenticationMethod -ModuleName Microsoft.Entra.Beta.SignIns -Times 1 -ParameterFilter { - $userId | Should -Be 'Test_contoso@M365x99297270.onmicrosoft.com' + $userId | Should -Be 'SawyerM@contoso.com' $true } } It "Should set correct PhoneAuthenticationMethodId" { - Reset-EntraBetaStrongAuthenticationMethodByUpn -UserPrincipalName 'Test_contoso@M365x99297270.onmicrosoft.com' + Reset-EntraBetaStrongAuthenticationMethodByUpn -UserPrincipalName 'SawyerM@contoso.com' Should -Invoke -CommandName Get-MgBetaUserAuthenticationMethod -ModuleName Microsoft.Entra.Beta.SignIns -Times 1 Should -Invoke -CommandName Remove-MgBetaUserAuthenticationPhoneMethod -ModuleName Microsoft.Entra.Beta.SignIns -Times 1 -ParameterFilter { - $userId | Should -Be 'Test_contoso@M365x99297270.onmicrosoft.com' - $PhoneAuthenticationMethodId | Should -Be 'bbbbbbbb-1111-2222-3333-cccccccccccc' + $userId | Should -Be 'SawyerM@contoso.com' + $PhoneAuthenticationMethodId | Should -Be 'b3f1c54f-1b1f-40fc-8d6d-cd4dc041e959' $true } } It "Should contain 'User-Agent' header" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Reset-EntraBetaStrongAuthenticationMethodByUpn" - Reset-EntraBetaStrongAuthenticationMethodByUpn -UserPrincipalName 'Test_contoso@M365x99297270.onmicrosoft.com' + Reset-EntraBetaStrongAuthenticationMethodByUpn -UserPrincipalName 'SawyerM@contoso.com' Should -Invoke -CommandName Get-MgBetaUserAuthenticationMethod -ModuleName Microsoft.Entra.Beta.SignIns -Times 1 -ParameterFilter { $Headers.'User-Agent' | Should -Be $userAgentHeaderValue $true @@ -66,7 +66,7 @@ Describe "Reset-EntraBetaStrongAuthenticationMethodByUpn" { try { # Act & Assert: Ensure the function doesn't throw an exception - { Reset-EntraBetaStrongAuthenticationMethodByUpn -UserPrincipalName 'Test_contoso@M365x99297270.onmicrosoft.com' -Debug } | Should -Not -Throw + { Reset-EntraBetaStrongAuthenticationMethodByUpn -UserPrincipalName 'SawyerM@contoso.com' -Debug } | Should -Not -Throw } finally { # Restore original confirmation preference