PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,823 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am retrieving lastsigninDateTime of users with MSGraph, and I came upon this error with one of the users. It seems like the string value has an added space or null character in this case for some reason, and it can't properly convert this to a Datetime value. So the Get-Type and the Get-Member functions don't return the same type of object for this particular variable ! What is happening here and how can I workaround this ?
Thanks in advance for your help !
PS C:\> $dt = $SignInActivity.lastsigninDateTime
PS C:\> $dt
September 15, 2022 4:59:56
PS C:\>if($lastLogonTS -lt $dt){echo "Anterior"}
Could not compare "09/15/2022 16:59:19" to "09/15/2022 16:59:56 ". Error: "Cannot convert the "System.Object[]" value of type "System.Object[]" to type "System.DateTime"."
PS C:\> $dt.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array
PS C:\> $dt | Get-Member
TypeName: System.DateTime
Name MemberType Definition
---- ---------- ----------
Add Method datetime Add(timespan value)
AddDays Method datetime AddDays(double value)
...
PS C:\> $dt.ToString()
System.Object[]
PS C:\> $dt.ToFileTimeUTC()
You cannot call a method on a null-valued expression.
At line:1 char:1
+ $dt.ToFileTimeUTC()
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull