The string was not recognized as a valid DateTime. There is an unknown word starting at index 0.

Good morning.

I am working on script to synchronize data from Servicenow to Active Roles. To do that, i have created a sync step in which SNOW is the source and ARS the target. In the updating rules, I have a forward sync rule in which I run my script.

The script basically modify the members of a given group from SNOW, using the Remove-QADGroupMember -Identity ($GroupName) -Member $c[$i] -Confirm:$false -Control @{'OperationReason'="Set by script"} // add-qadgroupmember -identity ($GroupName) -member $c[$i] -Control @{'OperationReason'="Set by script"}. This removes or add users to the group and create an entry in the change history.

However, as it is a sync task, I cannot get it working totally, always getting an error. In the beginning, I was synching the "members" target item (ARS attribute) and getting an error as the content of the members change before the script finishes.

Then I decided to try other options. First i went for one of the "Custom Attributes 10" that are available and there I got an error message saying that the attribute can only contain on value. What I could see in the details of the result window is that each user that were removed or added were included in the attribute + a "ActiveRoles.ManagementShell.Data.ArsServerConnection", that comes from the "Connect-QADService -proxy" to get the changes registered in the change history.

So the content of Custom attribute 10 would be ActiveRoles.ManagementShell.Data.ArsServerConnection, user1, user2, (blank). I added the blank with "Return $Null" to leave the attibute blank.
Then I tried with "WhenChanged" attribute and adding the current date with "[DateTime]$date=Get-Date -Format "dd.MM.yyyy HH:mm:ss"" // return $date, getting the error of the subject. i have tried with and without declaring the type of $date, and changing the format to how it is currently registered.

I have also tried to use "Flags" attribute, integer, giving some similar type error.

So I am assuming that every time that the users are added/deleted, they are added to the target item.

After the long explanation, the question, is there a way of pass only the result needed, independently of what the script does?

Would you do this in a different way? I cannot use a direct connection with SNOW, if you are going to suggest that.

Best regards

Top Replies

Parents
  • Parsing a string representation of a c# DateTime is a tricky thing because different cultures have different date formats. .Net is aware of these date formats and pulls them from your current culture (System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat) when you call DateTime.Parse(this.Text); You can either call DateTime.ParseExact and pass in the exact format string that you're expecting, or you can pass in an appropriate culture to DateTime.Parse to parse the date.

    For example, this will parse your date correctly:

    DateTime.Parse( "22/11/2009", CultureInfo.CreateSpecificCulture("fr-FR") );

    Of course, you shouldn't just randomly pick France, but something appropriate to your needs.

    What you need to figure out is what System.Threading.Thread.CurrentThread.CurrentCulture is set to, and if/why it differs from what you expect. The IFormatProvider parameter specifies the culture to use to parse the date. Unless your string comes from the user, you should pass CultureInfo.InvariantCulture. If the string does come from the user, you should pass CultureInfo.CurrentCulture, which will use the settings that the user specified in Regional Options in Control Panel.

Reply
  • Parsing a string representation of a c# DateTime is a tricky thing because different cultures have different date formats. .Net is aware of these date formats and pulls them from your current culture (System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat) when you call DateTime.Parse(this.Text); You can either call DateTime.ParseExact and pass in the exact format string that you're expecting, or you can pass in an appropriate culture to DateTime.Parse to parse the date.

    For example, this will parse your date correctly:

    DateTime.Parse( "22/11/2009", CultureInfo.CreateSpecificCulture("fr-FR") );

    Of course, you shouldn't just randomly pick France, but something appropriate to your needs.

    What you need to figure out is what System.Threading.Thread.CurrentThread.CurrentCulture is set to, and if/why it differs from what you expect. The IFormatProvider parameter specifies the culture to use to parse the date. Unless your string comes from the user, you should pass CultureInfo.InvariantCulture. If the string does come from the user, you should pass CultureInfo.CurrentCulture, which will use the settings that the user specified in Regional Options in Control Panel.

Children
No Data