Download presentation
Presentation is loading. Please wait.
1
CN1266 Network Scripting Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+
2
Agenda Chapter 13: Going On a Date with PowerShell Quiz Exercise
3
Date cmdlets Get-Date ▫-DisplayHint date ▫-DisplayHint time ▫-format yyyyMMdd Try: -format dd-mm-yyyy ▫-uFormat %y%m%d ▫See Table 13-1 on Page 177 for Modifiers
4
Creating your own dates If you omit any value, it will shows default value. ▫Time: 12:00:00 AM $mydate = Get-Date “03/29/2010” Get-Date –year 2010 –month 3 –day 29 –hour 14 –minute 23 –second 15
5
Using Date Math Calculating the differences ▫$date1 = Get-Date –year 1983 –month 2 –day 3 ▫$date2 = Get-Date –year 2010 –month 12 –day 25 ▫$diff = $date2-$date1 As a result, you will get TimeSpan object ▫To get specific result, we use property of TimeSpan ▫$diff.days ▫$diff.TotalHours
6
Looking into the future To schedule the task to run every 15 days: ▫$StartDate = Get-Date ▫Write-Host ("Task runs on: ") ▫Write-Host $StartDate ▫for($i = 15; $i -le 60; $i += 15){ ▫ Write-Host $StartDate.AddDays($i) ▫} Or to calculate the past ▫$now = get-Date ▫$now.AddHours(-8723)
7
Daylight Saving? $date1 = Get-Date "1/3/2008" $date2 = Get-Date "4/23/2008" $date1.IsDayLightSavingTime $date2.IsDayLightSavingTime
8
Time Zones In order to calculate the timezone different, ▫$tz = [timezone]::CurrentTimeZone ▫$d = Get-Date ▫$tz.getUTCoffset($d).Hours
9
Assignment See Hand out Write a fortune teller code to give the answer based on the time of the day (Minutes) ▫0 – 10 – answer 1 ▫11 – 20 – answer 2 ▫21- 30 – answer 3 ▫31- 40 – answer 4 ▫41- 50 – answer 5 ▫51- 59 – answer 6
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.