Get date isnt working properly

In have the follow script:

[system.reflection.assembly]::loadwithpartialname('microsoft.visualbasic') | Out-Null
$Country = [microsoft.visualbasic.interaction]::inputbox('Fill in the Country name in the short OU version','Country')
$StartDate = [microsoft.visualbasic.interaction]::inputbox('Fill in the begin date of the month','Given Date')
$EndDate = [microsoft.visualbasic.interaction]::inputbox('Fill in the last date of the month','Last Date') 
$fileLocation = [microsoft.visualbasic.interaction]::inputbox('give up filelocation were to save the file','Save As','c:\temp\data.csv')



$SDate = get-date $StartDate 
$EDate = get-date $EndDate 
$OurUsers = Get-ADUser -SearchBase "OU=$country,DC=corp,DC=local" -filter * -Properties *
$OurUsers | Where-Object {($_.whencreated -ge $StartDate) -and ($_.Whencreated -le $EndDate)} | 
Select-Object @{Name="AD DisplayName";Expression={$_.CN}}, @{Name="Accountname";Expression={$_.SamAccountName}},@{Name="Creation Date";Expression={$_.WhenCreated}}, @{Name="internal or external";Expression={$_.Extensionattribute6}}, @{Name="E-mail(if General account field can be Empty)";Expression={$_.Mail}}, @{Name="Notesfield";Expression={$_.Info}}, AccountExpirationDate, PasswordNeverExpires, CannotChangePassword, PasswordNotRequired| Sort-Object whencreated -Descending | 
Export-Csv $fileLocation -Delimiter ";" 

When i run this i get the follow message

Could not compare “01/25/2018 10:45:18” to “31-1-2018”. Error: “Cannot convert value “31-1-2018” to type “System.DateTime”. Error: “String was not recognized as a valid DateTime.””
At line:17 char:27

  • $OurUsers | Where-Object {($.whencreated -ge $StartDate) -and ($.Whencreated - …
  •                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (:slight_smile: , RuntimeException
    • FullyQualifiedErrorId : ComparisonFailure

I know the problem comes from the line:

$OurUsers | Where-Object {($_.whencreated -ge $StartDate) -and ($_.Whencreated -le $EndDate)} | 

Any one know what must be filled in.

With these 2 lines

$SDate = get-date $StartDate
$EDate = get-date $EndDate

you’re creating DateTime objects but you’re not using them. … should look like this:
$OurUsers | Where-Object {($.whencreated -ge $SDate) -and ($.Whencreated -le $EDate)} | 

i was just seconds to late to update this post,

Yeah is saw the problem, oh what freaking stupid but thank you for the support