Skip to content

Commit

Permalink
2.0.0.5 Get-XrmWhoAmI
Browse files Browse the repository at this point in the history
  • Loading branch information
Aymeric Mouillé committed Dec 22, 2024
1 parent 6ad3a56 commit 69dbdff
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
2 changes: 1 addition & 1 deletion PowerDataOps.psd1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@{
RootModule = 'PowerDataOps'
ModuleVersion = '2.0.0.4'
ModuleVersion = '2.0.0.5'
GUID = 'bfa11058-d4b5-4300-b74a-cdc3d9560389'
Author = 'Aymeric Mouillé'
CompanyName = 'Unknown'
Expand Down
3 changes: 1 addition & 2 deletions src/Security/Get-XrmUser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ function Get-XrmUser {
}
process {
if (-not $PSBoundParameters.ContainsKey('UserId')) {
# TODO : CrmServiceClient to ServiceClient migration.
# $UserId = $XrmClient.GetMyCrmUserId();
$UserId = Get-XrmWhoAmI -XrmClient $XrmClient;
}

$user = Get-XrmRecord -Logicalname "systemuser" -Id $UserId -Columns $Columns;
Expand Down
36 changes: 36 additions & 0 deletions src/Security/Get-XrmWhoAmI.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<#
.SYNOPSIS
Retrieve current user id.
.DESCRIPTION
Get system user unique identifier.
.PARAMETER XrmClient
Xrm connector initialized to target instance. Use latest one by default. (Dataverse ServiceClient)
#>
function Get-XrmWhoAmI {
[CmdletBinding()]
param
(
[Parameter(Mandatory = $false, ValueFromPipeline)]
[Microsoft.PowerPlatform.Dataverse.Client.ServiceClient]
$XrmClient = $Global:XrmClient
)
begin {
$StopWatch = [System.Diagnostics.Stopwatch]::StartNew();
Trace-XrmFunction -Name $MyInvocation.MyCommand.Name -Stage Start -Parameters ($MyInvocation.MyCommand.Parameters);
}
process {

$request = new-xrmrequest -Name "WhoAmI";
$response = Invoke-xrmRequest -XrmClient $XrmClient -Request $request;

$userId = $response.Results["UserId"].Guid;
$userId;
}
end {
$StopWatch.Stop();
Trace-XrmFunction -Name $MyInvocation.MyCommand.Name -Stage Stop -StopWatch $StopWatch;
}
}
Export-ModuleMember -Function Get-XrmWhoAmI -Alias *;
5 changes: 2 additions & 3 deletions src/Types/New-XrmContext.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ function New-XrmContext {
$object.CurrentConnection.Name = $XrmClient.OrganizationDetail.UrlName;
$object.CurrentConnection.Region = $XrmClient.OrganizationDetail.Geo;

# TODO : CrmServiceClient to ServiceClient migration.
# $userId = $XrmClient.GetMyCrmUserId();
# $object.UserId = $userId;
$userId = Get-XrmWhoAmI -XrmClient $XrmClient;
$object.UserId = $userId;
}

$object;
Expand Down

0 comments on commit 69dbdff

Please sign in to comment.