Have a problem with updating user account account expiry dates that is being fed in from a CSV file.
If I have just one record in the csv file, then it works and the account exipration date gets updated, but if I have two or more users listed in the file then I see this error…
“Set-ADAccountExpiration : Cannot convert ‘System.Object’ to the type ‘System.Nullable`1[System.DateTime]’ required by parameter ‘DateTime’. Specified method is not supported.At line:9 char:101 + CategoryInfo : InvalidArgument: ( [Set-ADAccountExpiration], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.ActiveDirectory.Management.Commands.SetADAccountE xpiration”…
The End Date Value shows “01/11/2020” and Get-Date shows “01 November 2020 00:00:00”
The reason I need to insert the following statement (somewhere into my statement), is that AD will populate the expiry date field to 31/10/2020…see link below which goes into detail why this happens.
[quote quote=199646]The End Date Value shows “01/11/2020” and Get-Date shows “01 November 2020 00:00:00”
The reason I need to insert the following statement (somewhere into my statement), is that AD will populate the expiry date field to 31/10/2020…see link below which goes into detail why this happens.[/quote]
So you may add a few hours to your “End Date value” to circumvent this issue
(Get-Date “01/11/2020”).AddHours(6).AddDays(1)
Maybe it depends on your time zone setting as well …
…thanks for getting back… I don’t think that would work as the date would need to be a variable.
just to recap…I need to import a CSV file, convert the date from a string into a date type, add +1 day and then feed this new date variable into the AD expiration field.
Hope that this is clear…otherwise I will have to try some alternative arrangement.
Would it hurt you if you tried? You told that a date of 1st of November will be “converted” to 31st of October. So I’d think it could be the case of some weird little automatic conversion in the background - maybe because of time zone differences or something like this. Just try it - I’m pretty sure it will not kill you.