Module 03-Lesson 4: Enumerating Objects in Windows PowerShell Pipeline using ForEach-Object command

preview_player
Показать описание
Automating Administration with Windows PowerShell is a series of course with Microsoft Official Courseware Material. To be become Zero to Hero in PowerShell please follow along my channel.

PowerShell Scripting For Beginners || Module 3: Working with the Windows PowerShell pipeline || Lesson 4: Enumerating objects in the pipeline ||

PowerShell Tutorial Playlist for ALL Modules:

📌 Subscribe to A Computer Guru channel for more Videos.

In this video i will be covering the following topics:

1. Purpose of enumeration
➜ Enumeration is the process of performing a task on each object, one at a time, in a collection.
➜ For example, if you need to stop every running Notepad process on your computer, you can run either of these two commands:

Get-Process –Name Notepad | Stop-Process
Stop-Process –Name Notepad

2. Basic enumeration syntax
➜ The ForEach-Object command performs enumeration. It has two common aliases: ForEach and %. Like Where-Object, ForEach-Object has a basic syntax and an advanced syntax
➜ In the basic syntax, you can run a single method or access a single property of the objects that were piped into the command. Here is an example:

Get-ChildItem –Path C:\Encrypted\ -File | ForEach-Object –MemberName Encrypt

➜ For example, both of the following commands perform the same action:

Get-ChildItem –Path C:\Encrypted\ -File | ForEach Encrypt
Get-ChildItem –Path C:\Encrypted\ -File | % Encrypt

3. Advanced enumeration syntax
➜ The advanced syntax for enumeration provides more flexibility and functionality than the basic syntax. Instead of letting you access a single object member, you can run a whole script. That script can include just one command, or it can include many commands in sequence
➜ For example, to encrypt a set of files by using the advanced syntax, type the following command in the console

Get-ChildItem –Path C:\ToEncrypt\ -File | ForEach-Object –Process { $PSItem.Encrypt() }

4. Advanced techniques
➜ In some situations, you might need to repeat a particular task a specified number of times. You can use ForEach-Object for that purpose when you pass it an input that uses the range operator. The range operator is two periods (..) with no space between them. For example, run the following command:

1..100 | ForEach-Object { Get-Random }

➜ the range operator produces integer objects from 1 through 100. Those 100 objects are piped to ForEach-Object, forcing the script block to run 100 times. However, because neither $_ nor $_PSItem appear in the script block, the actual integers are not used. Instead, the Get-Random command runs 100 times

***********************************************************************
🔗 Links to the previous videos 🔗

1. Introduction to Windows PowerShell
2. Overview and Background of Windows PowerShell
3. Lab A: Configuring Windows PowerShell
4. Understanding command syntax & Finding commands
5. Lab B: Finding and running basic commands
6. Active Directory administration cmdlets
7. Network configuration cmdlets & Other server administration cmdlets
8. Windows administration
9. Working with the Windows PowerShell pipeline 1.1
10. Working with the Windows PowerShell pipeline 1.2
11. Selecting, sorting, and measuring objects 2.1
12. Selecting, sorting, and measuring objects 2.2
13. Selecting, sorting, and measuring objects 2.3
14. Filtering objects out of the pipeline

📲 Follow A Computer Guru

#learnPowerShell #acomputerguru #powershellscripting #powershellforbeginners #acg #windowspowershell #devops #scripting #automation #PowerShell #PowerShellTutorial #azuretraining #azuretutorial #azureadministrator #azuretutorial #azurecourse #azurelab #azurehandsonlab #az104lab #PowerShelltraining
Рекомендации по теме
visit shbcf.ru