Link to home
Start Free TrialLog in
Avatar of PeterSinger
PeterSingerFlag for Australia

asked on

Powershell time within 2 minutes of listed

Hi,

I have a powershell script that I am comparing the two fields;
Get-QADGroup UGL-SM-Map.Shared-Full |ft ModificationDate, Description

ModificationDate                                            Description
----------------                                            -----------
13/09/2011 10:55:37 AM                                      13/09/2011 10:55:37 AM

ModificationDate                                            Description
----------------                                            -----------
13/09/2011 10:55:37 AM                                      13/09/2011 10:55:39 AM



I want to say if the date and time is -eq or within 2 minutes of each other then return true if not return false.

Help please :)
ASKER CERTIFIED SOLUTION
Avatar of KenMcF
KenMcF
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PeterSinger

ASKER

Thanks.

I get the below back;

Get-Date : Cannot bind parameter 'Date'. Cannot convert value "09/13/2011" to type "System.DateTime". Error: "String wa
s not recognized as a valid DateTime."
At D:\Scripts\SharedMailboxes\test.ps1:15 char:10
+     get-date <<<<  "$month/$day/$year" -Month $month -hour $hour -minute $minute
    + CategoryInfo          : InvalidArgument: (:) [Get-Date], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.GetDateCommand

Get-Date : Cannot bind parameter 'Date'. Cannot convert value "09/13/2011" to type "System.DateTime". Error: "String wa
s not recognized as a valid DateTime."
At D:\Scripts\SharedMailboxes\test.ps1:15 char:10
+     get-date <<<<  "$month/$day/$year" -Month $month -hour $hour -minute $minute
    + CategoryInfo          : InvalidArgument: (:) [Get-Date], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.GetDateCommand

New-TimeSpan : Cannot bind parameter 'End' to the target. Exception setting "End": "Object reference not set to an inst
ance of an object."
At D:\Scripts\SharedMailboxes\test.ps1:20 char:18
+ If ((New-TimeSpan <<<<  (Format-time $($group.ModificationDate)) (Format-time $($Group.Description))).minutes -le "2"
){
    + CategoryInfo          : WriteError: (:) [New-TimeSpan], ParameterBindingException
    + FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.PowerShell.Commands.NewTimeSpanCommand
$day and $month round the wron way.  Thenks working nicely.
Very Nice, thanks.