【发布时间】:2021-06-07 10:02:56
【问题描述】:
我在 PS 中有以下代码:
Connect-AzureAD
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
Get-AzureADUser -All:$true |Select ObjectId,UserPrincipalName,@{Name='ExpirationDate'; Expression={(Get-AzureADUserExtension -ObjectId $_.ObjectId).Get_Item("createdDateTime")}}
| Export-CSV "$PSScriptRoot\userslist.csv"
Disconnect-AzureAD
我想将字符串 createdDateTime 转换为 dateTime 格式,因此我可以向其添加 +60 天 (.AddDays(60))。我试过不转换,但没有用。
Expression={(...).Get_Item("createdDateTime")}}
我也尝试了函数 [datetime]::ParseExact 但我做错了(控制台中没有错误),因为输出中的列是空白的。
请指教
编辑 这是我运行 Pamela 给出的整个脚本后得到的。控制台没有错误。任何想法为什么会这样?
【问题讨论】:
-
您能否发布一个
createdDateTime的示例值,以便我们知道需要解析哪些值? -
我在输出中得到了这样的
CreationDate : 19.10.2020 13:55:29 -
我根本不相信
createdDateTime是一个字符串。这就是它被字符串化以供显示的方式。你能做一个Get_Item("createdDateTime").GetType()请确认它不是一个 DateTime 对象吗? -
@Theo 我做到了。它显示 System.String 类型
标签: azure powershell