Working With Pipeline
Working With Pipeline
• Example of use:
• Get-Service | Sort-Object Name -
Descending
Example: Sort-Object
Get-Service | Measure-Object
Get-Process |
Measure-Object –Prop PM –Sum -Average
Demonstration: Measuring Objects
Get-Service |
Sort-Object -Property Status |
Select-Object –First 10
Get-Process |
Sort VM –Descending |
Select –First 10
Selecting Properties of Objects
Get-Service |
Select-Object –Property Name,Status
Get-Process |
Sort PM –Descending |
Select –Property Name,ID,PM,VM –First
10
Demonstration: Selecting Objects
Hash table
@{
n='VirtualMemory';
e={ $PSItem.VM } Semicolon
} Expression Expression
key script block
Formatting Tips
Get-Volume |
Select-Object –Property DriveLetter,
@{
n='Size(GB)';
e={'{0:N2}' -f ($PSItem.Size / 1GB)}
},
@{
n='FreeSpace(GB)';
e={'{0:N2}' -f ($PSItem.SizeRemaining / 1GB)}
}
Demonstration: Creating Calculated
Properties
Logon Information
• Two verbs:
• ConvertTo changes the form of the data
• Export changes the form of the data and writes
it to external storage
Get-Service |
Sort-Object –Property Status |
Select-Object –Property Name,Status |
ConvertTo-CSV |
Out-File –FilePath ServiceList.csv
Demonstration: Converting and Exporting
Objects
Logon Information
Comparison Operators
Basic Filtering Syntax
Advanced Filtering Syntax
Demonstration: Filtering
• Optimizing Filtering Performance
Comparison Operators
Get-Service |
Where Status –eq Running
Get-Process |
Where CPU –gt 20
Limitations of the Basic Syntax
Get-Service |
Where-Object –Filter {$PSItem.Status –eq
'Running' }
Logon Information
• Cannot:
• Execute commands or code
• Evaluate expressions
• Make logical decisions
Demonstration: Basic Enumeration
Logon Information
Review Question(s)
Real-world Issues and Scenarios
Best Practice
• Common Issues and Troubleshooting Tips