Need help in setting the duration for role assignment using Azure PIM

SR VSP 1,226 Reputation points
2021-09-30T13:08:03.467+00:00

Team,

Can you help setting the correct time duration for a specific user like Ex: 4 hrs OR 12 hrs or 24hrs . Below code i'm using not working as expected for the time stamp.
It should always set the current system time.

Open-AzureADMSPrivilegedRoleAssignmentRequest -ProviderId 'aadRoles' -ResourceId 'fb108fc9-23c2-4d1e-b22e-ff2ew77623da' -RoleDefinitionId 'fe430be4-5e62-47db-91af-98c3a49a38b1' -SubjectId '504f2f84-5aa4-42e8-99eb-d1a509f69f78' -Type 'adminAdd' -AssignmentState 'Eligible' -schedule $schedule -reason "test using powershell"

**$Duration = 4 # Number in Hours**  
$Date = Get-Date  
$start = $Date.ToUniversalTime()  
$end = $Date.AddHours($Duration).ToUniversalTime()  

$schedule = New-Object Microsoft.Open.MSGraph.Model.AzureADMSPrivilegedSchedule  
$schedule.Type = 'Once'  
$schedule.StartDateTime = $start.ToString('yyyy-MM-ddTHH:mm:ss.fffZ')  
$schedule.endDateTime = $end.ToString('yyyy-MM-ddTHH:mm:ss.fffZ')  

@Sharon Zhao-MSFT

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,538 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,418 questions
{count} votes