AddHours(双精度值)添加指定小时数。 AddMinutes(双精度值)添加指定分钟数。 AddMonths(整数月份)添加指定月数。 AddYears(整数值)添加指定年份。 ToLongDateString()以字符串形式返回长格式的日期。 ToShortDateString()以字符串形式返回短格式的日期。 ToLongTimeString()以字符串形式返回长格式的时间。
AddTicks Method datetime AddTicks(long value) AddYears Method datetime AddYears(int value) CompareTo Method int CompareTo(System.Object value), int ... 你可以很快的看到 DateTime 对象具有一个AddDays方法,从而可以使用它来快速的获取昨天的日期: > (Get-Date).AddDays(-1) Saturday, January 20, 2018...
备注 Default 模式和 First 模式都返回第一个(numberToReturn)项,并且可以互换使用。LastPowerShell 复制 $h = (Get-Date).AddHours(-1) $logs = dir 'C:\' -Recurse '*.log' | Sort-Object CreationTime # Find the last 5 log files created in the past hour $logs.Where({$_.CreationTime -...
$startingDate = (Get-Date -Hour 00 -Minute 00 -Second 00).adddays(-$numberOfDays) 创建这些变量之后,您将在事件日志中检索事件,并将查询结果存储在 $events 变量中。使用 Get-EventLog cmdlet 来查询事件日志并将“system”指定为日志名称。在 Windows PowerShell 2.0 中,您可以使用 –source 参数来减少...
Get-Date|Format-Custom{$_}#$_表示管道中当前对象classDateTime{$_=classDateTime{Day=27DayOfWeek=Wednesday DayOfYear=331Hour=15Kind=Local Millisecond=132Minute=41Month=11Second=5Ticks=637104660651327983TimeOfDay=classTimeSpan{Ticks=564651327983Days=0Hours=15Milliseconds=132Minutes=41Seconds=5TotalDays=0.653531...
Hey, wait. I did some work on the weekend. I only want Friday! Well, we can filter on that, too, by using theAddDays()method to our date and give it a range of 24 hours! Get-ChildItem-PathC:\-Include*.doc,*.docx-File-Recurse-ErrorActionSilentlyContinue|Where-Object{$_.LastWriteTim...
$path="PSEvents_$($env:COMPUTERNAME)_$(Get-Date ((Get-Date).ToUniversalTime()) -Format yyyyMMddHHmmss).csv"$hours=1# Increase this to have it query more than just the last 1 hour$now=Get-Date$startTimeUtc=Get-Date($now.AddHours(-$hours).ToUniversalTime())-Format'yyyy-MM-ddT...
Add columns to PowerShell array and write the result to a table Add computer to AD group Add computers to domain in bulk / mass Add Computers to Security Group Based on OU Add current date to email subject line Add custom AD attribute to user depending on parent OU Add Custom Function to...
To get yesterday’s date (or tomorrow’s) you create a date and time object for today usingGet-Datewith no parameters. Then you use theAddDays()method to add/subtract some number of days, like this: Copy PSC:># Get today's DatePSC:>$Today=Get-DatePSC:>$Yesterday=$Today.AddDays(-...
$Date = (Get-Date).AddDays(-2) Get-WinEvent -FilterHashtable @{ LogName='Application'; StartTime=$Date; Id='1003' } The Get-Date cmdlet uses the AddDays method to get a date that is two days before the current date. The date object is stored in the $Date...