【发布时间】:2019-02-28 14:37:09
【问题描述】:
我遇到了将用户输入转换为DateTime 类型同时以特定格式返回的问题。我已经搜索了几个小时,到目前为止我尝试过的一切都没有奏效。
当我输入日期时,我希望它保持我输入的格式,以便Get-MessageTrace 可以读取它。
我正在寻找的是输入“2019 年 1 月 23 日”,ParseExact 会将其返回为“2019 年 1 月 23 日”。
我得到的是 $NewDate1 是“2019 年 1 月 23 日,星期三 12:01:00 AM”
我可能做的不对,或者做错了什么,但我需要一些帮助,拜托。
$UserEmail = Read-Host -Prompt 'Enter your WT email address'
$Date1 = Read-Host -Prompt 'Enter the first date (MM/DD/YYYY)'
$Date2 = (Read-Host -Prompt 'Enter the second date (MM/DD/YYYY)'
$NewDate1 = [datetime]::parseexact($Date1, 'm/d/yyyy', $null)
$NewDate2 = [datetime]::parseexact($Date2, 'm/d/yyyy', $null)
Get-MessageTrace -RecipientAddress 'UserEmail' -StartDate '$NewDate1'
-EndDate 'NewDate2'
我收到错误:
无法处理参数“StartDate”的参数转换。无法将值“$NewDate1”转换为类型 “系统。日期时间”。错误:“字符串未被识别为有效的日期时间。” + CategoryInfo : InvalidData: (:) [Get-MessageTrace], ParameterBindin...mationException + FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-MessageTrace + PSComputerName:outlook.office365.com
【问题讨论】:
标签: powershell office365