Temporary group membership

Hi, can someone suggest me how to set temporary group membership in ARS Version 6.9, I have tried with below mentioned command but the time is set to starting of temporary group membership but I am looking for end time and also I want to set reason as well to add some text like ticket number to it, could you please let me know.

Command:

Add-qadgroupmember -identity "groupname" -member 'accountname' -control @{'scheduledoperation-settime'=(set-date to-date "09/08/2020")}}

Parents
  • Having had a couple of issues recently myself, and double checking the SDK, the date required to be set in the ScheduledOperation-SetTime control is a GeneralizedDate. and I discussed the problem and talked throught the issue, with his assistance I came up with the below, Thanks Johnny.

    If you're using a value generated from Get-Date, this will work as you expect, however if you're converting it from a string (for instance you've imported it from a CSV), although you might use a covert method to get it into a date format, you may still have problem.

    The below function will convert it to a GeneralizedDate format, which you can pipe into the appropriate place in your script. This is something I've just created, so will need proper testing in your development environment to ensure it works in all your use cases.

    Function Convert-ToGeneralizedDate
    {
        Param
        (
            [string]$Date=$null,
            [string]$CurrentDateFormat = 'dd/MM/yyyy HH:mm:ss'
        )
    
        $WorkingDate = [datetime]::parseexact($Date, $CurrentDateFormat, $null)
        $DateElement = ($WorkingDate.ToString("yyyyMMdd")).Replace("/","")
        $TimeElement = ($WorkingDate.ToLongTimeString()).Replace(":","")
    
        $Result = [string]::Format("{0}{1}.{2}Z",$DateElement,$TimeElement,$WorkingDate.Millisecond)
        Return $Result
    }
    

    When you call the function, ensure that $CurrentDateFormat is set to the date format your data has the value held, in my case its always in the format "dd/MM/yyyy HH:mm:ss", IE:

    Function Convert-ToGeneralizedDate
    {
        Param
        (
            [string]$Date=$null,
            [string]$CurrentDateFormat = 'dd/MM/yyyy HH:mm:ss'
        )
    
        $WorkingDate = [datetime]::parseexact($Date, $CurrentDateFormat, $null)
        $DateElement = ($WorkingDate.ToString("yyyyMMdd")).Replace("/","")
        $TimeElement = ($WorkingDate.ToLongTimeString()).Replace(":","")
    
        $Result = [string]::Format("{0}{1}.{2}Z",$DateElement,$TimeElement,$WorkingDate.Millisecond)
        Return $Result
    }
    
    
    $GroupName = "Group1"
    $Member = "Test20"
    
    $StartTime = Convert-ToGeneralizedDate -Date "01/01/2022 09:00:00" -CurrentDateFormat "dd/MM/yyyy HH:mm:ss"
    $EndTime = Convert-ToGeneralizedDate -Date "01/01/2023 14:45:29" -CurrentDateFormat "dd/MM/yyyy HH:mm:ss"
    
    # Add Member - Temporal add
    Add-qadgroupmember -identity $GroupName -member $Member -control @{'scheduledoperation-settime'=$StartTime} -Proxy
    
    # Remove Member - Temporal remove
    Remove-QADGroupMember -identity $GroupName -member $Member -control @{'scheduledoperation-settime'=$EndTime} -Proxy

Reply
  • Having had a couple of issues recently myself, and double checking the SDK, the date required to be set in the ScheduledOperation-SetTime control is a GeneralizedDate. and I discussed the problem and talked throught the issue, with his assistance I came up with the below, Thanks Johnny.

    If you're using a value generated from Get-Date, this will work as you expect, however if you're converting it from a string (for instance you've imported it from a CSV), although you might use a covert method to get it into a date format, you may still have problem.

    The below function will convert it to a GeneralizedDate format, which you can pipe into the appropriate place in your script. This is something I've just created, so will need proper testing in your development environment to ensure it works in all your use cases.

    Function Convert-ToGeneralizedDate
    {
        Param
        (
            [string]$Date=$null,
            [string]$CurrentDateFormat = 'dd/MM/yyyy HH:mm:ss'
        )
    
        $WorkingDate = [datetime]::parseexact($Date, $CurrentDateFormat, $null)
        $DateElement = ($WorkingDate.ToString("yyyyMMdd")).Replace("/","")
        $TimeElement = ($WorkingDate.ToLongTimeString()).Replace(":","")
    
        $Result = [string]::Format("{0}{1}.{2}Z",$DateElement,$TimeElement,$WorkingDate.Millisecond)
        Return $Result
    }
    

    When you call the function, ensure that $CurrentDateFormat is set to the date format your data has the value held, in my case its always in the format "dd/MM/yyyy HH:mm:ss", IE:

    Function Convert-ToGeneralizedDate
    {
        Param
        (
            [string]$Date=$null,
            [string]$CurrentDateFormat = 'dd/MM/yyyy HH:mm:ss'
        )
    
        $WorkingDate = [datetime]::parseexact($Date, $CurrentDateFormat, $null)
        $DateElement = ($WorkingDate.ToString("yyyyMMdd")).Replace("/","")
        $TimeElement = ($WorkingDate.ToLongTimeString()).Replace(":","")
    
        $Result = [string]::Format("{0}{1}.{2}Z",$DateElement,$TimeElement,$WorkingDate.Millisecond)
        Return $Result
    }
    
    
    $GroupName = "Group1"
    $Member = "Test20"
    
    $StartTime = Convert-ToGeneralizedDate -Date "01/01/2022 09:00:00" -CurrentDateFormat "dd/MM/yyyy HH:mm:ss"
    $EndTime = Convert-ToGeneralizedDate -Date "01/01/2023 14:45:29" -CurrentDateFormat "dd/MM/yyyy HH:mm:ss"
    
    # Add Member - Temporal add
    Add-qadgroupmember -identity $GroupName -member $Member -control @{'scheduledoperation-settime'=$StartTime} -Proxy
    
    # Remove Member - Temporal remove
    Remove-QADGroupMember -identity $GroupName -member $Member -control @{'scheduledoperation-settime'=$EndTime} -Proxy

Children
No Data