在 Windows 10 上启动 PowerShell 7。
PowerShell 7.0.0
Copyright (c) Microsoft Corporation. All rights reserved.
https://aka.ms/powershell
Type 'help' to get help.
Warning: PowerShell detected that you might be using a screen reader and has disabled PSReadLine for compatibility purposes. If you want to re-enable it, run 'Import-Module PSReadLine'.
Run Code Online (Sandbox Code Playgroud)
PowerShell 启动时不显示警告,因为我没有使用屏幕阅读器。
运行指定的命令Import-Module PSReadLine
。自从我第一次想了解为什么会出现警告以来,我就没有运行过它。
$PSVersionTable
输出:Name Value
---- -----
PSVersion 7.0.0
PSEdition Core
GitCommitId 7.0.0
OS Microsoft Windows 10.0.18362
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, …
Run Code Online (Sandbox Code Playgroud) 我无法使用 Powershell 从某个日期获得时差,如下所示:
$Date = '11/12/2001'
(New-TimeSpan -Start (Get-Date -Date $Date) -End (Get-Date)).ToString("'yyyy' Years 'MM' Months 'dd' Days 'hh' Hours 'mm' Minutes 'ss' Seconds'")
Run Code Online (Sandbox Code Playgroud)
Exception calling "ToString" with "1" argument(s): "Input string was not in a correct format."
At line:2 char:1
+ (New-TimeSpan -Start (Get-Date -Date $Date) -End (Get-Date)).ToString ...
Run Code Online (Sandbox Code Playgroud)
为什么我不能得到年和月的过去?