I am trying to learn PowerShell using Learn Windows PowerShell3 In a Month of Lunches 2nd Edition
The Chapoter 9 Lab for number 4 had this question:
Write a command that uses pipeline parameter binding to retrieve a list of running processes from every computer in an AD domain.
Don’t use parentheses.
And this was the answer (which was the same answer that I came up with) but I do not think it is working correctly.
get-adcomputer -filter * | Select-Object @{Label=‘computername’;Expression={$_.name}} | Get-Process
Here is the result:
computername
LYNCDC6
LYNCSE6
LYNCEXUM6
MINTZ
from running this part of the command:
get-adcomputer -filter * | Select-Object @{Label=‘computername’;Expression={$_.name}}
Yet, when I run the entire command the results did NOT look correct.
So I modified the command and added a select and a sort:
get-adcomputer -filter * | Select-Object @{Label=‘computername’;expression={$_.name}} | Get-Process |
Select-Object -Property MachineName, ProcessName, Id, VirtualMemorySize | Sort-Object -Property Id
Now the results shown below tell me I was correct and the results were not what I expected:
MachineName ProcessName Id VirtualMemorySize
LYNCDC6 Idle 0 0
LYNCDC6 Idle 0 0
LYNCDC6 Idle 0 0
LYNCDC6 Idle 0 0
LYNCDC6 System 4 3461120
LYNCDC6 System 4 3461120
LYNCDC6 System 4 3461120
LYNCDC6 System 4 3461120
LYNCDC6 smss 280 4644864
…
Is it possible that PowerShell 4 needs a different command than PowerShell 3?
get-host
Name : ConsoleHost
Version : 4.0
InstanceId : d0f58f22-df14-4b5c-b4f0-6b18a2c1f636
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : en-US
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace