You are preparing a one-line PowerShell command to inventory running services on a Windows Server. The command must retrieve only services whose Status property is Running, convert the resulting objects to JSON, and then overwrite (not append) the file C:\Temp\RunningServices.json. Which pipeline satisfies all of these requirements?
The first pipeline gets all services, filters the objects to those whose Status is Running, converts the remaining objects to JSON, and then uses Set-Content with the -Force switch to write (and if necessary replace) the destination file. Set-Content replaces existing content, whereas Add-Content always appends; Out-File with -NoClobber prevents overwriting; and using -Append or omitting the Where-Object filter fails the stated requirements. In addition, Get-Service does not accept a -Status parameter in Windows PowerShell, so that alternative would generate an error. Therefore the first pipeline is the only one that fulfills every requirement.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is the purpose of the `Set-Content` cmdlet in PowerShell?
Open an interactive chat with Bash
Why does `Where-Object` use `$_` when filtering objects?
Open an interactive chat with Bash
What is the role of `ConvertTo-Json` in the pipeline?