Temporary group membership

HI,  I would like to add a group by midnight through a script, I know the GUI has the setting to set date and time but how would I do it using a script.

Command:

Add-QADgroupmember -identity "groupname" -member $ADuser   (tonight at midnight)

any help would be much appreciated  Slight smile

  • I had a script open, I had to remove bits (so you'll need to test in your lab environment), but to add to Johnny's link

    $Type = "Add"
    $Group = "<GroupDN>"
    $Member = "<MemberDN>"
    $Reason = "<Reason>"
    $SetTime = get-date -Date (Get-date).Date -Hour 00 -Minute 00 -Second 00
    $GroupDN =  Get-QADObject -Identity $Group
    $MemberDN = Get-QADObject -Identity $Member
       
    $ControlHash=@{}
    $ControlHash.Add("OperationReason","$Reason")
    $ControlHash.Add('ScheduledOperation-SetTime',$($SetTime))
    
    if($Type -eq "Add")
    {
    	$Add = Add-QADGroupMember -Identity $GroupDN.DN -Member $MemberDN.DN -Control $ControlHash -Proxy
    }
    ElseIf($Type -eq "Remove")
    {
    	$Remove = Remove-QADGroupMember -Identity $GroupDN.DN -Member $MemberDN.DN -Control $ControlHash -Proxy
    }
    Elsehttps://www.oneidentity.com/community/active-roles/f/forum/32839/temporary-group-membership/80088#
    {
    	Write-Host "Unhandled type ($($Type))"
    }

  • so would you say this is correct, to start at 10PM

    $SetTime = get-date -Date (Get-date).Date -Hour 22 -Minute 00 -Second 00
    $ControlHash=@{}
    $ControlHash.Add('ScheduledOperation-SetTime',$($SetTime))
    Add-qadgroupmember -identity "TheGroup" -members $user -Control $ControlHash -Proxy

  • Yes

    Bear in mind however, the time that gets set is based upon your local time... so in the UK for example, currently we are in British Summer Time (GMT+1 or UTC+1), therefore if I were to add at 10, it would shown in the console as 11....

    IE I ran this:

    And it resulted in this:

    As always time zones can result in your results appears differently, so take account of this when writing/running your script. There are methods to set the time as GMT/UTC, or to the offset you require.