-
Notifications
You must be signed in to change notification settings - Fork 1
/
Get-AccountAttributeAge.ps1
63 lines (57 loc) · 2.44 KB
/
Get-AccountAttributeAge.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
Function Get-AccountAttributeAge {
<#
.Synopsis
Parses provided ad account and returns a timespan object for the specified parameters
.DESCRIPTION
Takes an ad object as input. Based on the provided parameters and the swithes used, the output will be a timespan object representing the time between the current date and the timestamp of the attribute.
.EXAMPLE
get-aduser svc-app -properties * | Get-AccountAttributeAge -Logon
This example returns the amount of time since the account last logged in to the domain
.EXAMPLE
get-aduser svc-app -properties * | Get-AccountAttributeAge -Modify
This example returns the amount of time since the account was modified in any way
#>
[CmdletBinding(DefaultParameterSetName = "byInputObject")]
Param(
[Parameter(Mandatory=$True,ValueFromPipelinebyPropertyName=$True,ParameterSetName="Logon")]
[ValidateNotNullOrEmpty()]
$LastLogonTimestamp,
[Parameter(Mandatory=$True,ValueFromPipelinebyPropertyName=$True,ParameterSetName="Password")]
[ValidateNotNullOrEmpty()]
$PasswordLastSet,
[Parameter(Mandatory=$True,ValueFromPipelinebyPropertyName=$True,ParameterSetName="Modify")]
[ValidateNotNullOrEmpty()]
$whenChanged,
[Parameter(Mandatory=$True,
Position=1,
ParameterSetName="byInputObject")]
[System.Object]$InputObject,
[Parameter(ParameterSetName="Logon")]
[Switch]$Logon,
[Parameter(ParameterSetName="Password")]
[Switch]$Password,
[Parameter(ParameterSetName="Modify")]
[Switch]$Modify
)
BEGIN{
$Today = get-date
$BaseDate = [datetime]"January 1, 1601"
}
PROCESS{
If ($InputObject){
$inputObject | Get-AccountAttributeAge
}
else {
If ($logon){
$LastLogondate = $BaseDate.AddTicks($lastlogontimestamp)
$age = $today - $LastLogonDate
} elseif ($password) {
$age = $today - [datetime]$PasswordLastSet
} elseif ($Modify) {
$age = $today - [datetime]$whenChanged
}
$age
}
}
END{}
}