Need some help in modifying script to compare the current date time into Epoch time ?


hi all,

can here please assist me how correct below script can work comparing date & time stamp ?

$daysinactive = 180  $time = (get-date).adddays(-($daysinactive))    get-aduser -properties * -searchbase "ou=head office,dc=domain,dc=com" |   where-object {($_.lastlogontimestamp -le $time -or $_.lastlogontimestamp -notlike "*") -and ($_.passwordlastset -le $time) -and ($_.enabled -eq $true)} |   select-object name,@{n='last logon timestamp';e={[datetime]::fromfiletime($_.lastlogontimestamp)}}, passwordlastset, canonicalname

because error:

could not compare "130698308169494429" "07/24/2015 13:00:01". error: "cannot convert value "24/07/2015 1:00:01 pm" type "system.int64". error: "invalid cast 'datetime' 'int64'.""  @ c:\users\admin\appdata\local\temp\fc8e5dd3-5962-496c-9e59-eaf95b323be2.ps1:6 char:15  + ... ere-object {($_.lastlogontimestamp -le $time -or $_.lastlogontimestam ...  +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~      + categoryinfo          : invalidoperation: (:) [], runtimeexception      + fullyqualifiederrorid : comparisonfailure     not compare "130969882022825362" "07/24/2015 13:00:01". error: "cannot convert value "24/07/2015 1:00:01 pm" type "system.int64". error: "invalid cast 'datetime' 'int64'.""  @ c:\users\admin\appdata\local\temp\fc8e5dd3-5962-496c-9e59-eaf95b323be2.ps1:6 char:15  + ... ere-object {($_.lastlogontimestamp -le $time -or $_.lastlogontimestam ...  +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~      + categoryinfo          : invalidoperation: (:) [], runtimeexception      + fullyqualifiederrorid : comparisonfailure

thanks.


/* server support specialist */

sorry:

$time =[datetime]::today.adddays(-180) $filter={enabled -eq $true -and lastlogondate -le $time -and passwordlastset -le $time} $props='name','lastlogondate', 'passwordlastset', 'canonicalname' $search='ou=head office,dc=domain,dc=com'   get-aduser -searchbase $search -filter $filter -properties $props | select-object $props


\_(ツ)_/




Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

server manager error: ADAM.events.xml could not be enumerated.

Cannot access Anywhere Access using domain name?

WMI Failure: Unable to update Local Resource Group