I have a script that scans a list of servers/computers for a service and displays the status.
I am running PS version 5 Build 10586 Revision 117 on both of my computers.
On my Windows 7 computer running PSv5, the StartType is outputted to the .txt
MachineName ServiceName Status StartType
----------- ----------- ------ ---------
srvcomp0201 My.ServiceName.Here Stopped Stopped
srvcomp0202 My.OtherServiceName Running Running
When I run this same script on my Windows 2012 computer with PSv4 or v5, the StartType is not outputted to the .txt or .csv
MachineName ServiceName Status StartType
----------- ----------- ------ ---------
srvcomp0201 My.ServiceName.Here Stopped
srvcomp0202 My.OtherServiceName Running
I can change the order that is supposed to be displayed like:
$s | select MachineName, StartType, ServiceName, Status
And it still doesn't show anything when run on the Win2012 computer.
Why is it doing this?
$serviceList = Get-Content C:\services.txt
$results = Get-Content C:\servers.txt | ForEach-Object {
foreach ($service in $serviceList) {
if ($s=get-service -computer $_ -name $service -ErrorAction SilentlyContinue)
{
$s | select MachineName, StartType, ServiceName, Status | Out-File C:\test.txt -Append
} else {
"$_ - Service '$service' does not exist."
}
}
}
UPDATE
This doesn't write the StartType to the file either:
$serviceList = Get-Content C:\services.txt
$results = Get-Content C:\servers.txt | ForEach-Object {
foreach ($service in $serviceList) {
if ($s=get-service -computer $_ -name $service -ErrorAction SilentlyContinue)
{
$s | select MachineName, StartType | Out-File C:\test.txt -Append
} else {
"$_ - Service '$service' does not exist."
}
}
}
This doesn't display the StartType on my 2012 computer either:
get-content c:\servicelist\computers.txt | % {
if ($s=get-service -computer $_ -name W3SVC* -ErrorAction SilentlyContinue) # change -name * to name of service
{
$s | select MachineName, ServiceName, StartType, Status
}
else {"Service is not available on $_"}
}
Is this a Windows 2012 thing?