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

标签 powershell

我有一个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/

相关文章:

powershell - 如何检查响应 header 是否包含某些 header powershell

powershell - 使用 hg purge 时排除目录

PowerShell:If 语句并在 Import-CSV 中使用空白单元格

powershell - 在 InvokeSBFarmUpgrade 上重建索引

windows - 如何从 Windows 上的命令行查看命名管道权限

powershell - 根据另一个组合框的选择填充组合框 - Powershell

powershell - 如何在不输入 y 的情况下使用 ssh-keygen 和 PowerShell 覆盖现有的 SSH key 文件

powershell - 用于客户端计算机的PowerShell DSC?

powershell - 使用 Powershell 阅读 Gmail 电子邮件

用于根据创建年份清除文件的 Powershell 脚本