英文:
Howto format datevalues where result contains several date fields
问题
以下是翻译好的部分:
'用户1','用户2' | foreach-object {
get-aduser -identity $_ -Properties * |
select name,DisplayName,samaccountname,enabled, accountexpirationdate,whenchanged }| ft
name DisplayName samaccountname enabled accountexpirationdate whenchanged
---- ----------- -------------- ------- --------------------- -----------
user1, 我的姓名, user1 False 11-04-2023 00:00:00 11-04-2023 00:42:21
user2, 我的姓名, user2 False 11-04-2023 00:00:00 11-04-2023 00:42:21
请告诉我您需要如何格式化日期字段为短日期格式。
英文:
'user1','user2' | foreach-object {
get-aduser -identity $_ -Properties * |
select name,DisplayName,samaccountname,enabled, accountexpirationdate,whenchanged }| ft
name DisplayName samaccountname enabled accountexpirationdate whenchanged
---- ----------- -------------- ------- --------------------- -----------
user1, MyName, user1 False 11-04-2023 00:00:00 11-04-2023 00:42:21
user2, MyName, user2 False 11-04-2023 00:00:00 11-04-2023 00:42:21
I want to have all the date fields formatted as shortdates
I have tried to add -format string to each datefield without success
答案1
得分: 1
这应该能满足你的需求
'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
在需要的地方更改每个条目中的格式位,以调整返回的确切日期格式。
英文:
This should do what you're looking for
'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
where you can tweak the exact date format being returned by changing the format bit in each
@{n='ExpirationDate';e={Get-Date $_.accountexpirationdate -Format 'dd-MM-yy'}}
entry as needed.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论