I have the following code which prints out some properties of each SQL Server related service on a host:
[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.SqlWmiManagement")|Out-Null;
$mc = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer localhost;
$mc.Services | % {$_|select-object Name,DisplayName,ServiceState}
I want to output the result with the HostName appended. I've tried this:
$hostName = hostname
$mc.Services | % {$_|select-object Name,DisplayName,ServiceState,@{Name="HostName";Expression={$hostname}}
But I just get >> displayed. Any ideas on how to accomplish what I want?