powershell - 外出时的 Powershell 脚本
问题描述
我正在运行以下 PS1 脚本:
$userIdentity = "Firstname.Lastname"
$startTime = "06/13/18 13:00:00"
$endTime = "06/14/18 18:00:00"
$internalMessage = "Internal Message"
$externalMessage = "External Message"
Set-MailboxAutoReplyConfiguration -Identity $userIdentity -InternalMessage $internalMessage -ExternalMessage $externalMessage -AutoReplyState Scheduled -StartTime "$startTime" -EndTime "$endTime"
但它失败并出现以下错误:
Cmdlet error with following error message:
System.Management.Automation.ParentContainsErrorRecordException:
Cannot process argument transformation on parameter 'StartTime'
Cannot convert value "13/06/2018 13:00:00" to type "System.DateTime".
Error: "String was not recognized as a valid DateTime."
它看起来像一个 system.datetime 格式问题,即英国而不是美国格式或类似的格式,但如下:
[datetime] "06/13/18 13:00:00"
返回
13 June 2018 13:00:00
所以系统显然可以翻译它 - 任何帮助将不胜感激!
谢谢
解决方案
我们最近也遇到了这个问题。
我们注意到的是,如果 Set-MailboxAutoReplyConfiguration 命令用于文化在“en-us”之外的 shell,它将无法正确解析日期。
在你的 powershell 会话中使用它来检查文化;
[System.Threading.Thread]::CurrentThread.CurrentCulture
如果不是“en-us”,请尝试将您的操作系统显示语言设置为“en-us”(确保区域设置为“匹配 Windows 显示语言”)。您应该在更改语言后重新加载 shell。
一旦我们在 en-us 地区,日期解析得很好。
推荐阅读
- reactjs - 如果您必须拆分代码以提高性能,那么单页大型应用程序的意义何在?
- arrays - 通过引用函数传递二维数组
- javascript - 如何在JS中将一个对象数组中的属性值添加到另一个对象(对于匹配的对象)
- macos - dyld:惰性符号绑定失败:找不到符号:____chkstk_darwin
- javascript - 为 Django 实现数据输入表前端的标准方法
- flask - 如何通过 Flask RESTful API 在 Web 应用程序中正确加载和使用 word2vec 模型?
- powershell - 有没有办法让批处理代码更紧凑?
- python - 将 python 字典从 {key : [x, y, z]} 反转为 {x: key, y : key, z : key}
- javascript - MongoDB查找带有日期比较的查询(NodeJs)
- android - 将 Xamarin 应用程序从 Windows 部署到本地手机说成功,但我在手机上看不到该应用程序?