PowerHuntShares icon indicating copy to clipboard operation
PowerHuntShares copied to clipboard

Date format

Open sleewharry opened this issue 3 years ago • 9 comments

hello, It seems that tool can not recognize share creation date. Error is: [*][08/15/2022 12:41] - Identified top 5 share names. Cannot convert value "16.07.2016 8:04:24 AM" to type "System.DateTime". Error: "String was not recognized as a valid DateTime."

thanks!

sleewharry avatar Aug 15 '22 11:08 sleewharry

Hey @sleewharry,

Thanks for the call out! I have not run into that in the lab or during testing. Can you tell me what version of Windows and PowerShell you are running?

nullbind avatar Aug 24 '22 12:08 nullbind

Hi @nullbind OS: Windows 10 Version 2004 (OS Build 19041.450) PS: 5.1.19041.1

This is the line that PS is complaining about: $ExPrivCreationLastn = $ExcessiveSharePrivs | Where-Object {([Datetime]$_.CreationDate.trim() -ge $StartDateAccess -and [Datetime]$_.CreationDate.trim() -le $EndDateAccess)}

2022-08-24 15_46_56-Window

sleewharry avatar Aug 24 '22 13:08 sleewharry

Hello, I have the exact same problem, I don't know a lot about powershell but it looks like an issue about the locale

Impossible de convertir la valeur « 26/08/2022 10:32:46 » en type « System.DateTime ». Erreur : « La chaîne n'a pas été reconnue en tant que DateTime valide. »
Au caractère Ligne:4844 : 54
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument : (:) [], RuntimeException
    + FullyQualifiedErrorId : InvalidCastParseTargetInvocationWithFormatProvider

Moonbeam4520 avatar Oct 06 '22 07:10 Moonbeam4520

Hello, I've modified ligne 553 to 568 and added the following code to the date to string conversion "{0:MM/dd/yyyy HH:mm:ss}" -f

This seem to have made the trick on my computer that mix french and english language, I am sure there is a better way to do it.

                  # Creation date
                  $CreationdDateObject = Get-Item "\\$TargetAsset\$CurrentShareName" -ErrorAction SilentlyContinue | Select CreationTime
                  $CreationdDate = ("{0:MM/dd/yyyy HH:mm:ss}" -f ($CreationdDateObject.CreationTime)).ToString()
                  $CreationdDateYear = $CreationdDateObject.CreationTime.Year.ToString()

                  # Last modified date
                  $TargetPath = $_.Path
                  $LastModifiedDateObject = Get-Item "\\$TargetAsset\$CurrentShareName" -ErrorAction SilentlyContinue | Select-Object LastWriteTime
                  $LastModifiedDate = ("{0:MM/dd/yyyy HH:mm:ss}" -f ($LastModifiedDateObject.LastWriteTime)).ToString()
                  $LastModifiedDateYear  = $LastModifiedDate.split(' ')[0].split('/')[2]

                  # Last accessed date
                  $TargetPath = $_.Path
                  $LastAccessDateObject = Get-Item "\\$TargetAsset\$CurrentShareName" -ErrorAction SilentlyContinue | Select-Object LastAccessTime
                  $LastAccessDate = ("{0:MM/dd/yyyy HH:mm:ss}" -f ($LastAccessDateObject.LastAccessTime)).ToString()
                  $LastAccessDateYear = $LastAccessDate.split(' ')[0].split('/')[2]

jegillet-debug avatar Oct 20 '22 14:10 jegillet-debug

Hi,

Thanks @jegillet-debug: the fix is working for me too (French locale)

Cool34000 avatar May 22 '23 20:05 Cool34000

Hey Everyone,

I'll try to get that fixed in the near future. Thanks for reaching out and sharing the solution!

nullbind avatar Jun 01 '23 21:06 nullbind

Danish locals here. Windows 11. PowerShell 7.3.6

Cannot convert value "26-04-2023 13:29:31" to type "System.DateTime". Error: "String was not recognized as a valid DateTime."
At (...path...)\PowerHuntShares.psm1:4844 char:54
+ ... ere-Object {([Datetime]$_.LastAccessDate.trim() -ge $startDate -and [ ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvalidCastParseTargetInvocationWithFormatProvider

LOLCATATONIA avatar Sep 07 '23 15:09 LOLCATATONIA