Interactive PowerShel script to add a user in AD temporarily

Hi guys,
Please , i would like to create an interactive script that adds a user to a group in AD, for a temporary period.
so far, it’s ok, but I want to add a control on the maximum possible duration (5 days for example ), and If you enter a maximum of 5 days, you send a message (duration too long! you need a number less than 5 for example).

And another control which will send an email to inform that such user has been added to AD group “x”.

this is the script :

Add-ADGroupMember -Identity “Direction” -Members “Florian” -MemberTimeToLive (New-TimeSpan -Days 2)

Thank you for your answers,

Good day,

b m,
Welcome to the forum. :wave:t3:

When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in PowerShell.org 1 <---- Click :point_up_2:t4: :wink:

You forgot to ask a question. :wink: