【发布时间】:2019-02-28 19:32:05
【问题描述】:
我正在从 WMI 获取有关监视器的信息。有称为“WeekOfManufacture”和“YearOfManufacture”的属性。在这种情况下是:
周:24 年份 : 2009我正在尝试获取与此相对应的大致日期。
我这样做是为了得到一个非常粗略的估计:
(Get-Date -Date $YearOfManufacture/01/01).AddDays(7*$WeekOfManufacture)
但显然“周”不一定总是有 7 天。
最好的方法是什么?
我现在使用的完整代码是:
$Monitors = Get-WmiObject WmiMonitorID -Namespace root\wmi
foreach ($Monitor in $Monitors) {
$Manufacturer = ($Monitor.ManufacturerName -notmatch 0 | ForEach{[char]$_}) -join ""
$Code = ($Monitor.ProductCodeID -notmatch 0 | ForEach{[char]$_}) -join ""
$Name = ($Monitor.UserFriendlyName -notmatch 0 | ForEach{[char]$_}) -join ""
$Serial = ($Monitor.SerialNumberID -notmatch 0 | ForEach{[char]$_}) -join ""
$WeekOfManufacture = $Monitor.WeekOfManufacture
$YearOfManufacture = $Monitor.YearOfManufacture
$DateManufacture = (get-date -Date $YearOfManufacture/01/01).AddDays(7*$WeekOfManufacture)
"$Manufacturer - $Code - $Name - $Serial - $DateManufacture"
}
返回类似(信息混淆):
SAM - 1234 - SycMastr - XXXX - 06/18/2009 00:00:00 SAM - 1234 - SycMastr - XXXX - 09/10/2009 00:00:00【问题讨论】:
-
您可以使用 .DayOfWeek 属性。前任。
$DateManufacture = (get-date -Date $YearOfManufacture/01/01).DayOfWeek确定是否是工作日和/或其他属性 -
十年±7天?谁在乎?
标签: powershell date week-number