gpt4 book ai didi

powershell - 修改值时的Powershell选择对象和更改属性名称

转载 作者:行者123 更新时间:2023-12-03 00:02:14 26 4
gpt4 key购买 nike

我有一个Cmdlet Get-AdUser,正在传递给选择对象,在该选择中,在AccountExpires属性上运行函数以将Property Value转换为日期值。

我的问题是,当对象输出时,列标题不再友好,并且继承了用于返回新值的函数。如何形成该语句,以便输出友好名称?希望不必组装我自己的PSObject。

Get-AdUser "some.account" -Properties AccountExpires | select Enabled, Name, $({[datetime]$d =$_.AccountExpires; ConvertTo-Date($d)})

然后我得到一个结果表头...
Enabled       True       [datetime]$d =$_.AccountExpires; ConvertTo-Date($d)
------- ----- ----------------------------------------------------

最佳答案

使用@{E={scriptblock};L="Label"}的表达式哈希表。
select Enabled, Name, @{E={$({[datetime]$d =$_.AccountExpires; ConvertTo-Date($d)})};L="AccountExpires"}
有关创建自定义选定对象的更多信息,请参见http://technet.microsoft.com/en-us/library/ee692794.aspx

关于powershell - 修改值时的Powershell选择对象和更改属性名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22317205/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com