Mit dem ForEach-Object (Alias foreach) werden einzelne oder alle Werte eines Objekts ausgelesen. Im folgenden Beispiel in der Powershell ISE werden Name und Status der Dienste angezeigt:
Clear-Host $dienste = Get-Service foreach ($_ in $dienste) {"{0,-35}: {1}" -f $_.Name, $_.Status}
AJRouter : Stopped ALG : Stopped AnyDesk : Running AppIDSvc : Stopped Appinfo : Running AppMgmt : Stopped AppReadiness : Stopped AppVClient : Stopped AppXSvc : Stopped AssignedAccessManagerSvc : Stopped AudioEndpointBuilder : Running Audiosrv : Running AxInstSV : Stopped BcastDVRUserService_3e3f03 : Stopped BDESVC : Stopped BFE : Running BITS : Stopped BluetoothUserService_3e3f03 : Stopped BrokerInfrastructure : Running Browser : Stopped BTAGService : Stopped .....
Kürzer geht es mit:
Get-Service
PS C:\> Get-Service Status Name DisplayName ------ ---- ----------- Stopped AJRouter AllJoyn-Routerdienst Stopped ALG Gatewaydienst auf Anwendungsebene Running AnyDesk AnyDesk Service Stopped AppIDSvc Anwendungsidentität Running Appinfo Anwendungsinformationen Stopped AppMgmt Anwendungsverwaltung Stopped AppReadiness App-Vorbereitung Stopped AppVClient Microsoft App-V Client Stopped AppXSvc AppX-Bereitstellungsdienst (AppXSVC) Stopped AssignedAccessM... AssignedAccessManager-Dienst Running AudioEndpointBu... Windows-Audio-Endpunkterstellung