我不擅长'user1','user2' | foreach对象{ 获取-aduser -identity $_ -Properties *
| select name,
DisplayName, samaccountname, enabled, accountexpirationdate, `
什么时候改变}|英尺
name DisplayName samaccountname enabled accountexpirationdate whenchanged
user1,MyName,user1 假 11-04-2023 00:00:00 11-04-2023 00:42:21 用户 2,我的名字,用户 2 假 11-04-2023 00:00:00 11-04-2023 00:42:21
我想将所有日期字段格式化为短日期
我尝试将 -format 字符串添加到每个日期字段但没有成功
这应该可以满足您的需求
'user1','user2' | foreach-object {
get-aduser -identity $_ -Properties * |
select name,DisplayName,samaccountname,enabled,@{n='ExpirationDate';e={Get-Date $_.accountexpirationdate -Format 'dd-MM-yy'}},@{n='WhenChanged';e={Get-Date $_.whenchanged -Format 'dd-MM-yy'}}
}| ft
您可以在其中通过更改每个中的格式位来调整返回的确切日期格式
@{n='ExpirationDate';e={Get-Date $_.accountexpirationdate -Format 'dd-MM-yy'}}
根据需要进入。