# ============================================================================================== # # Microsoft PowerShell Source File -- Created with SAPIEN Technologies PrimalScript 2007 # # NAME: Get-OtherDate.ps1 # # AUTHOR: Jeffery Hicks , SAPIEN Technologies, Inc. # DATE : 8/29/2008 # # COMMENT: use this function to simplify the process of getting a different datetime value # based on the current date # # ============================================================================================== Function Get-OtherDate { Param([datetime]$date=(Get-Date), [int32]$years=0, [int32]$months=0, [int32]$days=0, [int32]$hours=0, [int32]$minutes=0, [int32]$seconds=0, [int32]$milliseconds=0 ) [datetime]$dt=$date if ($milliseconds -ne 0) {$dt=$dt.AddMilliseconds($milliseconds)} if ($seconds -ne 0) {$dt=$dt.AddSeconds($seconds)} if ($minutes -ne 0) {$dt=$dt.AddMinutes($minutes)} if ($hours -ne 0) {$dt=$dt.AddHours($hours)} if ($days -ne 0) {$dt=$dt.AddDays($days)} if ($months -ne 0) {$dt=$dt.AddMonths($months)} if ($years -ne 0) {$dt=$dt.AddYears($years)} write $dt } Set-Alias od Get-OtherDate #Sample usage # Get-OtherDate -months 1 -days 11 -hours 7 # Get-OtherDate -days -45 # Get-OtherDate "7/4/2008" -days 90 # Get-OtherDate 12:34 -hours 4 # [ADSI]$admin="WinNT://$env:computername/Administrator,user" # $lastset=od -s (-$admin.passwordage.value) # $expires=od $lastset -day 60 # Write-host ("Password for {0} last set {1} and expires {2}" -f $admin.name.value,$lastset,$expires )-foreground CYAN