get-localuser |fl brings back the Date in that format:
PasswordExpires : 10/01/2022 15:31:34
我怎樣才能從現在開始以秒為單位計算這個日期?用powershell?有人可以幫我嗎?
AccountExpires :
Description :
Enabled : True
FullName : test-deleteme
PasswordChangeableDate : 29/11/2021 15:31:34
PasswordExpires : 10/01/2022 15:31:34
UserMayChangePassword : True
PasswordRequired : True
PasswordLastSet : 29/11/2021 15:31:34
LastLogon :
Name : test-deleteme
PrincipalSource : Local
ObjectClass : User
uj5u.com熱心網友回復:
該值的PasswordExpired值本身沒有特定格式 - 但 PowerShell 會在需要將其輸出到螢屏時根據您的區域設定選擇默認格式。
如果要計算從現在到 中指定日期的持續時間,請在計算屬性中PasswordExpiration使用減法運算子 ( -) :
Get-LocalUser |Select-Object Name,@{Name='PasswordExpiresInSeconds'; Expression={$_.PasswordExpires - (Get-Date)}}
這將產生一個[timespan]描述持續時間的值。要僅獲取秒數,請參考TotalSeconds生成的 timespan 物件上的屬性:
Get-LocalUser |Select-Object Name,@{Name='PasswordExpiresInSeconds'; Expression={$($_.PasswordExpires - (Get-Date)).TotalSeconds -as [int]}}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/370394.html
標籤:电源外壳
