Dieses Dokument beschreibt alle in der README.md erwähnten PowerShell-Befehle mit Syntax, Beispielen und Erklärungen.
Listet Dateien und Ordner in einem Verzeichnis auf.
Syntax: Get-ChildItem [-Path] <string[]> [-Filter <string>] [-Include <string[]>] [-Exclude <string[]>] [-Recurse] [-Force] [-File] [-Directory]
Beispiel: Get-ChildItem -Path C:\ -Filter *.txt -Recurse
Beschreibung: Gibt FileInfo- oder DirectoryInfo-Objekte zurück. Alias: dir, ls.
Links & Ressourcen:
- Offizielle Dokumentation: https://learn.microsoft.com/powershell/module/microsoft.powershell.management/get-childitem
- PowerShell-Pipeline Übersicht: https://learn.microsoft.com/powershell/scripting/learn/ps101/03-pipelines
Holt ein spezifisches Item (Datei oder Ordner).
Syntax: Get-Item [-Path] <string[]> [-Force]
Beispiel: Get-Item -Path C:\file.txt
Beschreibung: Ähnlich Get-ChildItem, aber für einzelne Items.
Links & Ressourcen:
- Offizielle Dokumentation: https://learn.microsoft.com/powershell/module/microsoft.powershell.management/get-item
Ändert Eigenschaften eines Items (selten für Dateien verwendet).
Syntax: Set-Item [-Path] <string[]> [-Value] <Object> [-Force]
Beispiel: Set-Item -Path C:\file.txt -Value "new content"
Beschreibung: Meist für Registry oder andere Provider.
Links & Ressourcen:
- Offizielle Dokumentation: https://learn.microsoft.com/powershell/module/microsoft.powershell.management/set-item
Erstellt neue Dateien oder Ordner.
Syntax: New-Item [-Path] <string[]> -ItemType <string> [-Value <Object>] [-Force]
Beispiel: New-Item -Path C:\NewFolder -ItemType Directory
Beschreibung: Erstellt Items wie Dateien oder Ordner.
Links & Ressourcen:
- Offizielle Dokumentation: https://learn.microsoft.com/powershell/module/microsoft.powershell.management/new-item
Löscht Dateien oder Ordner.
Syntax: Remove-Item [-Path] <string[]> [-Recurse] [-Force] [-Confirm] [-WhatIf]
Beispiel: Remove-Item -Path C:\file.txt -WhatIf
Beschreibung: Alias: del, rm. Verwende -WhatIf für Sicherheit.
Links & Ressourcen:
- Offizielle Dokumentation: https://learn.microsoft.com/powershell/module/microsoft.powershell.management/remove-item
Filtert Objekte in der Pipeline.
Syntax: Where-Object [-FilterScript] <scriptblock>
Beispiel: Get-ChildItem | Where-Object { $_.Length -gt 1MB }
Beschreibung: Alias: ?. Filtert basierend auf Bedingungen.
Links & Ressourcen:
- Offizielle Dokumentation: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/where-object
Sortiert Objekte.
Syntax: Sort-Object [-Property] <Object[]> [-Descending] [-Unique]
Beispiel: Get-ChildItem | Sort-Object Length -Descending
Beschreibung: Sortiert nach Eigenschaften.
Links & Ressourcen:
- Offizielle Dokumentation: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/sort-object
Wählt Eigenschaften oder Objekte aus.
Syntax: Select-Object [-Property] <Object[]> [-First <int>] [-Last <int>]
Beispiel: Get-ChildItem | Select-Object Name, Length
Beschreibung: Alias: select. Erstellt berechnete Properties möglich.
Links & Ressourcen:
- Offizielle Dokumentation: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/select-object
Holt Access Control Lists (Berechtigungen).
Syntax: Get-Acl [-Path] <string[]>
Beispiel: Get-Acl -Path C:\file.txt
Beschreibung: Zeigt Berechtigungen an.
Links & Ressourcen:
- Offizielle Dokumentation: https://learn.microsoft.com/powershell/module/microsoft.powershell.security/get-acl
Setzt Access Control Lists.
Syntax: Set-Acl [-Path] <string[]> -AclObject <Object>
Beispiel: $acl = Get-Acl C:\file.txt; Set-Acl -Path C:\file2.txt -AclObject $acl
Beschreibung: Kopiert oder ändert Berechtigungen.
Links & Ressourcen:
- Offizielle Dokumentation: https://learn.microsoft.com/powershell/module/microsoft.powershell.security/set-acl
Berechnet Hashes für Dateien.
Syntax: Get-FileHash [-Path] <string[]> [-Algorithm <string>]
Beispiel: Get-FileHash -Path C:\file.txt -Algorithm SHA256
Beschreibung: Für Integritätsprüfungen.
Links & Ressourcen:
- Offizielle Dokumentation: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/get-filehash
Kopiert Dateien oder Ordner.
Syntax: Copy-Item [-Path] <string[]> [-Destination] <string> [-Recurse] [-Force]
Beispiel: Copy-Item -Path C:\source -Destination C:\dest -Recurse
Beschreibung: Alias: copy, cp.
Links & Ressourcen:
- Offizielle Dokumentation: https://learn.microsoft.com/powershell/module/microsoft.powershell.management/copy-item
Verschiebt Dateien oder Ordner.
Syntax: Move-Item [-Path] <string[]> [-Destination] <string> [-Force]
Beispiel: Move-Item -Path C:\file.txt -Destination C:\dest
Beschreibung: Alias: move, mv.
Links & Ressourcen:
- Offizielle Dokumentation: https://learn.microsoft.com/powershell/module/microsoft.powershell.management/move-item
Sucht in Textdateien nach Mustern.
Syntax: Select-String [-Path] <string[]> [-Pattern] <string[]> [-Encoding <string>]
Beispiel: Select-String -Path *.log -Pattern "ERROR"
Beschreibung: Für inhaltsbasierte Suche.
Links & Ressourcen:
- Offizielle Dokumentation: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/select-string
Startet einen Prozess (z.B. externe Tools wie Robocopy).
Syntax: Start-Process [-FilePath] <string> [-ArgumentList <string[]>] [-Wait]
Beispiel: Start-Process robocopy -ArgumentList $source, $dest -Wait
Beschreibung: Für Integration mit externen Programmen.
Links & Ressourcen:
- Offizielle Dokumentation: https://learn.microsoft.com/powershell/module/microsoft.powershell.management/start-process
Misst Eigenschaften von Objekten (z.B. Summe, Durchschnitt).
Syntax: Measure-Object [-Property] <string[]> [-Sum] [-Average]
Beispiel: Get-ChildItem | Measure-Object -Property Length -Sum
Beschreibung: Für Aggregationen wie Größenberechnungen.
Links & Ressourcen:
- Offizielle Dokumentation: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/measure-object
Gruppiert Objekte nach Eigenschaften.
Syntax: Group-Object [-Property] <Object[]>
Beispiel: Get-ChildItem | Group-Object Length | Where-Object Count -gt 1
Beschreibung: Für Duplikatsfindung.
Links & Ressourcen:
- Offizielle Dokumentation: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/group-object
Ändert Eigenschaften von Items (z.B. Zeitstempel).
Syntax: Set-ItemProperty [-Path] <string[]> -Name <string> -Value <Object>
Beispiel: Set-ItemProperty -Path C:\file.txt -Name LastWriteTime -Value (Get-Date)
Beschreibung: Für Metadaten-Änderungen.
Links & Ressourcen:
- Offizielle Dokumentation: https://learn.microsoft.com/powershell/module/microsoft.powershell.management/set-itemproperty
Exportiert Objekte als CSV.
Syntax: Export-Csv [-Path] <string> [-InputObject <psobject>] [-NoTypeInformation]
Beispiel: Get-ChildItem | Export-Csv -Path report.csv
Beschreibung: Für Reports.
Links & Ressourcen:
- Offizielle Dokumentation: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/export-csv
Schreibt Ausgabe in eine Datei.
Syntax: Out-File [-FilePath] <string> [-InputObject <psobject>] [-Encoding <string>]
Beispiel: Get-ChildItem | Out-File -FilePath log.txt
Beschreibung: Für Logging.
Links & Ressourcen:
- Offizielle Dokumentation: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/out-file
Schreibt auf die Konsole.
Syntax: Write-Host [-Object] <Object[]> [-ForegroundColor <ConsoleColor>]
Beispiel: Write-Host "Hallo" -ForegroundColor Green
Beschreibung: Für Benutzer-Feedback.
Links & Ressourcen:
- Offizielle Dokumentation: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/write-host
Schreibt Fehlerausgaben.
Syntax: Write-Error [-Message] <string> [-Category <ErrorCategory>]
Beispiel: Write-Error "Fehler aufgetreten"
Beschreibung: Für Fehlerbehandlung.
Links & Ressourcen:
- Offizielle Dokumentation: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/write-error
Erstellt PSDrives für Provider.
Syntax: New-PSDrive [-Name] <string> -PSProvider <string> -Root <string>
Beispiel: New-PSDrive -Name Z -PSProvider FileSystem -Root \\Server\Share
Beschreibung: Für benutzerdefinierte Laufwerke.
Links & Ressourcen:
- Offizielle Dokumentation: https://learn.microsoft.com/powershell/module/microsoft.powershell.management/new-psdrive
Führt Skriptblöcke für jedes Objekt aus.
Syntax: ForEach-Object [-Process] <scriptblock>
Beispiel: Get-ChildItem | ForEach-Object { $_.Name }
Beschreibung: Alias: %. Für Iterationen.
Links & Ressourcen:
- Offizielle Dokumentation: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/foreach-object
Überprüft, ob ein Pfad existiert.
Syntax: Test-Path [-Path] <string[]> [-PathType <TestPathType>]
Beispiel: Test-Path -Path C:\folder
Beschreibung: Für Existenzprüfungen.
Links & Ressourcen:
- Offizielle Dokumentation: https://learn.microsoft.com/powershell/module/microsoft.powershell.management/test-path
Kombiniert Pfade.
Syntax: Join-Path [-Path] <string[]> -ChildPath <string>
Beispiel: Join-Path -Path C:\ -ChildPath subfolder
Beschreibung: Für sichere Pfad-Konstruktion.
Links & Ressourcen:
- Offizielle Dokumentation: https://learn.microsoft.com/powershell/module/microsoft.powershell.management/join-path
Holt das aktuelle Datum/Zeit.
Syntax: Get-Date [-Format <string>]
Beispiel: Get-Date -Format "yyyy-MM-dd"
Beschreibung: Für Zeitstempel.
Links & Ressourcen:
- Offizielle Dokumentation: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/get-date
Komprimiert Dateien in ZIP-Archive.
Syntax: Compress-Archive [-Path] <string[]> -DestinationPath <string> [-CompressionLevel <string>]
Beispiel: Compress-Archive -Path C:\folder -DestinationPath C:\archive.zip
Beschreibung: Für Backup-Erstellung.
Links & Ressourcen:
- Offizielle Dokumentation: https://learn.microsoft.com/powershell/module/microsoft.powershell.archive/compress-archive