powershell - 无法在 PowerShell 中组合 2 个命令
问题描述
我正在尝试使以下 PowerShell 命令工作但失败了。任何人都知道如何让这个工作?
我知道 Expression 标签中有问题,但不知道是什么。
Get-BrokerDesktop -MaxRecordCount 5000 | Where{($_.LastConnectionUser -eq $null) -and ($_.AssociatedUserNames -ne $null)} | Select MachineName,@{ Name = 'CreationDate'; Expression = {Get-ProvVM -MaxRecordCount 5000 -Filter "VMName -eq $_.HostedMachineName" | Select CreationDate}} | ft -AutoSize
它只给出第一列输出。显示第二列名称但没有数据。
如果我如下分别运行第二个命令,我将得到输出。
Get-ProvVM -MaxRecordCount 5000 -Filter "VMName -eq 'ComputerName'" | Select CreationDate
HostedMachineName
是 的一个属性Get-BrokerDesktop
。
VMName
是 的一个属性Get-ProvVM
。
解决方案
@Theo,谢谢,您的解决方案有效,但我必须根据需要添加-ExpandProperty
。这是我的最终命令,它完全按预期工作。
Get-BrokerDesktop -MaxRecordCount 5000 | Where{($_.LastConnectionUser -eq $null) -and ($_.AssociatedUserNames -ne $null)} | Select MachineName,@{ Name = 'CreationDate'; Expression = {Get-ProvVM -MaxRecordCount 5000 -Filter "VMName -eq '$($_.HostedMachineName)'" | Select CreationDate -ExpandProperty CreationDate}} | ft -AutoSize
推荐阅读
- .net - 通过 MVC 的邮件不显示不同 IE 的图像
- python - 了解 NumPy 2D 数组子设置中方括号的行为差异
- oracle - plsql 多案例,正则表达式匹配
- node.js - 运行 WebdriverIO 测试时抛出“无法创建新会话”错误
- arguments - 使用 jq 和多个变量创建一个 json 文件
- javascript - 我们可以在 angular(2/4/5/6) 中使用多个库,因为它支持 TreeShaking 吗?在不影响性能和构建大小的情况下
- angular - “路由器插座”不是已知元素 - 角度
- arrays - JSON 数组解析错误
- excel - 单击超链接时,在使用 [HttpGet] 的控制器操作上生成 404 错误?
- django - 选择一个有效的选项 ModelMultipleChoiceField 错误