I need to combine the output of two areas in a single line for each server. I am trying to find what is the best way to do that.
$servers=Get-ContentC:\Temp\srv.txt
$collection= $()
foreach ($serverin$servers)
{
Get-ADComputer-Filter {Name-Like$server} -ServerMyCompany.domain.com-Property*|selectName,Created,Enabled,LastLogonDate,OperatingSystem|Export-Csv-LiteralPathC:\Temp\S_ServerInAdInfo.csv-NoTypeInformation-Append
}
Gives:
Name | Created | Enabled | LastLogonDate | OperatingSystem |
MYDEVSERVER1 | 12/6/2007 10:52 | TRUE | 11/11/2014 17:09 | Windows Server 2003 |
MYDEVSERVER2 | 12/7/2007 10:52 | TRUE | 11/12/2014 17:09 | Windows Server 2008 |
But I want to use the following command in the same script so I can get service Info for those servers as shown below (highlighted in yellow)
$HealthService=Get-WmiObjectwin32_service-ComputerName$server-Filter"Name = 'SNMPTRAP'"-ErrorActionSilentlyContinue|selectState
Name | Created | Enabled | LastLogonDate | OperatingSystem | State |
MYDEVSERVER1 | 12/6/2007 10:52 | TRUE | 11/11/2014 17:09 | Windows Server 2003 | Stopped |
MYDEVSERVER2 | 12/7/2007 10:52 | TRUE | 11/12/2014 17:09 | Windows Server 2008 | Running |
Thanks in advance.