0203 | The pipeline | Getting Connected
Intro into the pipeline
- simple idea: take some object, send it through the pipeline (not just the string representaiton of it)
- pipe character:
|
- example
get-service | select-object name, status | sort-object name
# is the same as
get-service |
select-object name, status |
sort-object name
Current object crossing the pipeline
- either
$_.
or$PSItem.
Example | Services
# stop a specific service
get-service -name bits | stop-service
# rerun the service -- display the results
get-service -name bits | start-service -passthru
# export the services to a csv file
get-service | export-csv -Path c:\service.csv
# and import it back
import-csv c:\service.csv
Example | Debugging Processes
# take a snapshot of the running processes - on tha baseline machine
get-process | export-clixmd -path c:\good.xml
# compare it to the machine you are debugging
Compare-Object -ReferenceObject (Import-Clixml 'C:\good.xml') -DifferenceObject (Get-Process) -Property name
Converto vs Export
- export is converto and out
Example | Exporting services in an HTML format
get-service | convertto-html -property name, status | out-file c:\test.html
# check it
c:\test.html
If Unsure
- "When in trouble, fear or doubt, run in circles, scream and shout" :D
- show exactly what it would do
- if unsure, use
-whatif
- example
get-service | stop-service -whatif
Confirm (whatif
with confirm
)
- show what it would do and ask if you want to do it
- example
get-service | stop-service -confirm
# or to stop one right away and save time
get-service -displayname *bi* | stop-service -confirm