Powershell 是否计算属性以显示多个服务状态未工作?
我想知道如何更正以下计算的建筑红线:Powershell 是否计算属性以显示多个服务状态未工作?,powershell,Powershell,我想知道如何更正以下计算的建筑红线: @{ n = 'DFS Service Status'; e = { (Get-Service -Name DFS* -ComputerName $ENV:ComputerName | FL ) } }, 结果是: DFS Service Status Microsoft.PowerShell.Commands.Internal.Format.FormatStartData Microsoft.PowerShell.Commands.Internal.Fo
@{ n = 'DFS Service Status'; e = { (Get-Service -Name DFS* -ComputerName $ENV:ComputerName | FL ) } },
结果是:
DFS Service Status
Microsoft.PowerShell.Commands.Internal.Format.FormatStartData Microsoft.PowerShell.Commands.Internal.Format.GroupStartData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.GroupEndData Microsoft.PowerShell.Commands.Internal.Format.FormatEndData
根据项目事务处的意见:
我想得到'DisplayName-Status','DisplayName-Status'[…],因为我想转换HTML并以电子邮件的形式发送
记住这一点,您需要保留输入对象的属性,然后让converttohtml
处理属性值的“字符串化”:
# ConvertTo-Html will inspect the input objects and use the `DisplayName` and `Status`
# properties as column values in the HTML table
$html = Get-Service -Name DFS* |ConvertTo-Html -Property DisplayName,Status -Title "DFS Service Status" -As Table
# ...
Send-MailMessage ... -Body $html -BodyAsHtml
您希望输出是什么?如果服务正在运行,请更换
。|FL
带|选择-Expand Status
猜测太多,请创建一个,另请参见:。是的,我想获得'DisplayName-Status','DisplayName-Status',…您肯定不想将原始字符串传输到转换为HTML
谢谢!我感谢你在这件事上的帮助。