<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="de">
	<id>https://mediawiki.gerhardfoschum.me/index.php?action=history&amp;feed=atom&amp;title=Powershell_-_Arbeiten_mit_dem_Dateisystem</id>
	<title>Powershell - Arbeiten mit dem Dateisystem - Versionsgeschichte</title>
	<link rel="self" type="application/atom+xml" href="https://mediawiki.gerhardfoschum.me/index.php?action=history&amp;feed=atom&amp;title=Powershell_-_Arbeiten_mit_dem_Dateisystem"/>
	<link rel="alternate" type="text/html" href="https://mediawiki.gerhardfoschum.me/index.php?title=Powershell_-_Arbeiten_mit_dem_Dateisystem&amp;action=history"/>
	<updated>2026-11-16T17:47:35Z</updated>
	<subtitle>Versionsgeschichte dieser Seite in Gerhards Wiki</subtitle>
	<generator>MediaWiki 1.44.0</generator>
	<entry>
		<id>https://mediawiki.gerhardfoschum.me/index.php?title=Powershell_-_Arbeiten_mit_dem_Dateisystem&amp;diff=95&amp;oldid=prev</id>
		<title>Gerhard: Die Seite wurde neu angelegt: „== Kursübersicht ==  &#039;&#039;&#039;Voraussetzungen:&#039;&#039;&#039; Kurs 1-6 abgeschlossen  &#039;&#039;&#039;Lernziele:&#039;&#039;&#039; * Du navigierst effizient im Dateisystem * Du verwaltest Dateien und Ordner professionell * Du liest und schreibst Dateiinhalte * Du manipulierst Pfade sicher * Du arbeitest mit Dateieigenschaften und ACLs * Du automatisierst Dateisystem-Operationen  ----  == Modul 7.1: Navigation im Dateisystem ==  === Grundlegende Navigation ===  &lt;syntaxhighlight lang=&quot;powershell&quot;&gt; # A…“</title>
		<link rel="alternate" type="text/html" href="https://mediawiki.gerhardfoschum.me/index.php?title=Powershell_-_Arbeiten_mit_dem_Dateisystem&amp;diff=95&amp;oldid=prev"/>
		<updated>2025-12-21T18:07:26Z</updated>

		<summary type="html">&lt;p&gt;Die Seite wurde neu angelegt: „== Kursübersicht ==  &amp;#039;&amp;#039;&amp;#039;Voraussetzungen:&amp;#039;&amp;#039;&amp;#039; Kurs 1-6 abgeschlossen  &amp;#039;&amp;#039;&amp;#039;Lernziele:&amp;#039;&amp;#039;&amp;#039; * Du navigierst effizient im Dateisystem * Du verwaltest Dateien und Ordner professionell * Du liest und schreibst Dateiinhalte * Du manipulierst Pfade sicher * Du arbeitest mit Dateieigenschaften und ACLs * Du automatisierst Dateisystem-Operationen  ----  == Modul 7.1: Navigation im Dateisystem ==  === Grundlegende Navigation ===  &amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt; # A…“&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Neue Seite&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Kursübersicht ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Voraussetzungen:&amp;#039;&amp;#039;&amp;#039; Kurs 1-6 abgeschlossen&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Lernziele:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
* Du navigierst effizient im Dateisystem&lt;br /&gt;
* Du verwaltest Dateien und Ordner professionell&lt;br /&gt;
* Du liest und schreibst Dateiinhalte&lt;br /&gt;
* Du manipulierst Pfade sicher&lt;br /&gt;
* Du arbeitest mit Dateieigenschaften und ACLs&lt;br /&gt;
* Du automatisierst Dateisystem-Operationen&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Modul 7.1: Navigation im Dateisystem ==&lt;br /&gt;
&lt;br /&gt;
=== Grundlegende Navigation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Aktuelles Verzeichnis anzeigen&lt;br /&gt;
Get-Location&lt;br /&gt;
pwd  # Alias&lt;br /&gt;
&lt;br /&gt;
# Verzeichnis wechseln&lt;br /&gt;
Set-Location C:\Windows&lt;br /&gt;
cd C:\Windows  # Alias&lt;br /&gt;
&lt;br /&gt;
# Relative Pfade&lt;br /&gt;
Set-Location ..\Users       # Eine Ebene hoch, dann Users&lt;br /&gt;
Set-Location .\Documents    # Unterordner Documents&lt;br /&gt;
&lt;br /&gt;
# Spezielle Pfade&lt;br /&gt;
Set-Location ~              # Home-Verzeichnis des Benutzers&lt;br /&gt;
Set-Location $env:TEMP      # Temp-Ordner&lt;br /&gt;
Set-Location $env:USERPROFILE  # Benutzerprofil&lt;br /&gt;
&lt;br /&gt;
# Zurück zum vorherigen Verzeichnis&lt;br /&gt;
Set-Location -              # Toggle zwischen letzten zwei Pfaden&lt;br /&gt;
&lt;br /&gt;
# Mehrere Ebenen hoch&lt;br /&gt;
Set-Location ..\..\..\&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Location-Stack ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Aktuellen Pfad auf Stack pushen&lt;br /&gt;
Push-Location C:\Windows&lt;br /&gt;
Push-Location C:\Temp&lt;br /&gt;
Push-Location C:\Program Files&lt;br /&gt;
&lt;br /&gt;
# Location-Stack anzeigen&lt;br /&gt;
Get-Location -Stack&lt;br /&gt;
&lt;br /&gt;
# Zurück zum vorherigen Pfad&lt;br /&gt;
Pop-Location&lt;br /&gt;
Get-Location  # Jetzt in C:\Temp&lt;br /&gt;
&lt;br /&gt;
Pop-Location&lt;br /&gt;
Get-Location  # Jetzt in C:\Windows&lt;br /&gt;
&lt;br /&gt;
# Mehrere Locations auf einmal poppen&lt;br /&gt;
Pop-Location -StackName MyStack&lt;br /&gt;
&lt;br /&gt;
# Stack leeren&lt;br /&gt;
Get-Location -Stack | ForEach-Object { Pop-Location }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Verzeichnisinhalt anzeigen ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Dateien und Ordner auflisten&lt;br /&gt;
Get-ChildItem&lt;br /&gt;
ls    # Alias (Unix-Style)&lt;br /&gt;
dir   # Alias (DOS-Style)&lt;br /&gt;
gci   # Alias (Kurzform)&lt;br /&gt;
&lt;br /&gt;
# Nur Dateien&lt;br /&gt;
Get-ChildItem -File&lt;br /&gt;
&lt;br /&gt;
# Nur Ordner&lt;br /&gt;
Get-ChildItem -Directory&lt;br /&gt;
&lt;br /&gt;
# Rekursiv (mit Unterordnern)&lt;br /&gt;
Get-ChildItem -Recurse&lt;br /&gt;
&lt;br /&gt;
# Mit Filter&lt;br /&gt;
Get-ChildItem -Filter &amp;quot;*.txt&amp;quot;&lt;br /&gt;
Get-ChildItem -Filter &amp;quot;test*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Include/Exclude&lt;br /&gt;
Get-ChildItem -Include &amp;quot;*.log&amp;quot;, &amp;quot;*.txt&amp;quot; -Recurse&lt;br /&gt;
Get-ChildItem -Exclude &amp;quot;*.tmp&amp;quot; -Recurse&lt;br /&gt;
&lt;br /&gt;
# Versteckte Dateien einschließen&lt;br /&gt;
Get-ChildItem -Force&lt;br /&gt;
&lt;br /&gt;
# Tiefe begrenzen&lt;br /&gt;
Get-ChildItem -Recurse -Depth 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Pfad-Wildcards ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Wildcard !! Bedeutung !! Beispiel&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;*&amp;lt;/code&amp;gt; || Beliebige Zeichen || &amp;lt;code&amp;gt;*.txt&amp;lt;/code&amp;gt; = alle .txt Dateien&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;?&amp;lt;/code&amp;gt; || Genau ein Zeichen || &amp;lt;code&amp;gt;test?.txt&amp;lt;/code&amp;gt; = test1.txt, testa.txt&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;[abc]&amp;lt;/code&amp;gt; || Zeichen aus Menge || &amp;lt;code&amp;gt;file[123].txt&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;[a-z]&amp;lt;/code&amp;gt; || Zeichen aus Bereich || &amp;lt;code&amp;gt;[a-z]*.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Beispiele&lt;br /&gt;
Get-ChildItem *.txt                    # Alle .txt&lt;br /&gt;
Get-ChildItem test?.log                # test1.log, testA.log&lt;br /&gt;
Get-ChildItem file[123].txt           # file1.txt, file2.txt, file3.txt&lt;br /&gt;
Get-ChildItem [a-m]*.doc              # Dateien die mit a-m beginnen&lt;br /&gt;
Get-ChildItem *[0-9][0-9].log         # Dateien die mit 2 Ziffern enden&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Modul 7.2: Dateien und Ordner erstellen ==&lt;br /&gt;
&lt;br /&gt;
=== New-Item ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Ordner erstellen&lt;br /&gt;
New-Item -Path &amp;quot;C:\Temp\TestOrdner&amp;quot; -ItemType Directory&lt;br /&gt;
&lt;br /&gt;
# Mehrere Ebenen erstellen&lt;br /&gt;
New-Item -Path &amp;quot;C:\Temp\Projekt\Daten\Backup&amp;quot; -ItemType Directory -Force&lt;br /&gt;
&lt;br /&gt;
# Datei erstellen&lt;br /&gt;
New-Item -Path &amp;quot;C:\Temp\test.txt&amp;quot; -ItemType File&lt;br /&gt;
&lt;br /&gt;
# Datei mit Inhalt erstellen&lt;br /&gt;
New-Item -Path &amp;quot;C:\Temp\notiz.txt&amp;quot; -ItemType File -Value &amp;quot;Hallo Welt&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Mehrere Dateien auf einmal&lt;br /&gt;
1..10 | ForEach-Object {&lt;br /&gt;
    New-Item -Path &amp;quot;C:\Temp\datei$_.txt&amp;quot; -ItemType File&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Symbolischen Link erstellen&lt;br /&gt;
New-Item -Path &amp;quot;C:\Temp\Link&amp;quot; -ItemType SymbolicLink -Target &amp;quot;C:\Windows&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Hard Link&lt;br /&gt;
New-Item -Path &amp;quot;C:\Temp\hardlink.txt&amp;quot; -ItemType HardLink -Target &amp;quot;C:\Temp\original.txt&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Ordner-Struktur erstellen ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Projekt-Struktur erstellen&lt;br /&gt;
$projektPfad = &amp;quot;C:\Projekte\MeinProjekt&amp;quot;&lt;br /&gt;
&lt;br /&gt;
$struktur = @(&lt;br /&gt;
    &amp;quot;$projektPfad\Quellcode\src&amp;quot;&lt;br /&gt;
    &amp;quot;$projektPfad\Quellcode\tests&amp;quot;&lt;br /&gt;
    &amp;quot;$projektPfad\Dokumentation&amp;quot;&lt;br /&gt;
    &amp;quot;$projektPfad\Ausgabe\Debug&amp;quot;&lt;br /&gt;
    &amp;quot;$projektPfad\Ausgabe\Release&amp;quot;&lt;br /&gt;
    &amp;quot;$projektPfad\Ressourcen\Bilder&amp;quot;&lt;br /&gt;
    &amp;quot;$projektPfad\Ressourcen\Icons&amp;quot;&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
foreach ($pfad in $struktur) {&lt;br /&gt;
    if (-not (Test-Path $pfad)) {&lt;br /&gt;
        New-Item -Path $pfad -ItemType Directory -Force | Out-Null&lt;br /&gt;
        Write-Host &amp;quot;✓ Erstellt: $pfad&amp;quot; -ForegroundColor Green&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Write-Host &amp;quot;`nProjekt-Struktur erstellt!&amp;quot; -ForegroundColor Cyan&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Temporäre Dateien/Ordner ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Temporären Ordner erstellen&lt;br /&gt;
$tempOrdner = Join-Path $env:TEMP &amp;quot;MeinSkript_$(Get-Date -Format &amp;#039;yyyyMMdd_HHmmss&amp;#039;)&amp;quot;&lt;br /&gt;
New-Item -Path $tempOrdner -ItemType Directory&lt;br /&gt;
&lt;br /&gt;
# Temporäre Datei&lt;br /&gt;
$tempDatei = [System.IO.Path]::GetTempFileName()&lt;br /&gt;
Write-Host &amp;quot;Temp-Datei: $tempDatei&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Mit eindeutigem Namen&lt;br /&gt;
$tempDatei = Join-Path $env:TEMP &amp;quot;temp_$(New-Guid).txt&amp;quot;&lt;br /&gt;
New-Item -Path $tempDatei -ItemType File&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Modul 7.3: Dateien und Ordner löschen, kopieren, verschieben ==&lt;br /&gt;
&lt;br /&gt;
=== Remove-Item ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Datei löschen&lt;br /&gt;
Remove-Item -Path &amp;quot;C:\Temp\test.txt&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Ordner löschen (leer)&lt;br /&gt;
Remove-Item -Path &amp;quot;C:\Temp\LeererOrdner&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Ordner mit Inhalt löschen&lt;br /&gt;
Remove-Item -Path &amp;quot;C:\Temp\OrdnerMitDateien&amp;quot; -Recurse&lt;br /&gt;
&lt;br /&gt;
# Mit Bestätigung&lt;br /&gt;
Remove-Item -Path &amp;quot;C:\Temp\wichtig.txt&amp;quot; -Confirm&lt;br /&gt;
&lt;br /&gt;
# Ohne Bestätigung erzwingen&lt;br /&gt;
Remove-Item -Path &amp;quot;C:\Temp\schreibgeschuetzt.txt&amp;quot; -Force&lt;br /&gt;
&lt;br /&gt;
# Mehrere Dateien nach Pattern&lt;br /&gt;
Remove-Item -Path &amp;quot;C:\Temp\*.tmp&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# WhatIf - Simulation&lt;br /&gt;
Remove-Item -Path &amp;quot;C:\Temp\*&amp;quot; -Recurse -WhatIf&lt;br /&gt;
&lt;br /&gt;
# Mit Fehlerbehandlung&lt;br /&gt;
try {&lt;br /&gt;
    Remove-Item -Path &amp;quot;C:\Temp\datei.txt&amp;quot; -ErrorAction Stop&lt;br /&gt;
    Write-Host &amp;quot;Gelöscht&amp;quot;&lt;br /&gt;
} catch {&lt;br /&gt;
    Write-Warning &amp;quot;Konnte nicht löschen: $_&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Copy-Item ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Datei kopieren&lt;br /&gt;
Copy-Item -Path &amp;quot;C:\Quelle\datei.txt&amp;quot; -Destination &amp;quot;C:\Ziel\datei.txt&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Datei kopieren und umbenennen&lt;br /&gt;
Copy-Item -Path &amp;quot;C:\Quelle\alt.txt&amp;quot; -Destination &amp;quot;C:\Ziel\neu.txt&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Ordner kopieren (rekursiv)&lt;br /&gt;
Copy-Item -Path &amp;quot;C:\Quelle\Ordner&amp;quot; -Destination &amp;quot;C:\Ziel\Ordner&amp;quot; -Recurse&lt;br /&gt;
&lt;br /&gt;
# Mehrere Dateien&lt;br /&gt;
Copy-Item -Path &amp;quot;C:\Quelle\*.txt&amp;quot; -Destination &amp;quot;C:\Ziel\&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Mit Überschreiben&lt;br /&gt;
Copy-Item -Path &amp;quot;C:\Quelle\datei.txt&amp;quot; -Destination &amp;quot;C:\Ziel\&amp;quot; -Force&lt;br /&gt;
&lt;br /&gt;
# Container ohne Inhalt&lt;br /&gt;
Copy-Item -Path &amp;quot;C:\Quelle\Ordner&amp;quot; -Destination &amp;quot;C:\Ziel\Ordner&amp;quot; -Container&lt;br /&gt;
&lt;br /&gt;
# Mit Filter&lt;br /&gt;
Get-ChildItem &amp;quot;C:\Quelle&amp;quot; -Filter &amp;quot;*.log&amp;quot; | Copy-Item -Destination &amp;quot;C:\Ziel\Logs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Mit Fortschritt&lt;br /&gt;
$dateien = Get-ChildItem &amp;quot;C:\Quelle&amp;quot; -Recurse -File&lt;br /&gt;
$gesamt = $dateien.Count&lt;br /&gt;
$aktuell = 0&lt;br /&gt;
&lt;br /&gt;
foreach ($datei in $dateien) {&lt;br /&gt;
    $aktuell++&lt;br /&gt;
    Write-Progress -Activity &amp;quot;Kopiere Dateien&amp;quot; -Status &amp;quot;$aktuell von $gesamt&amp;quot; -PercentComplete (($aktuell / $gesamt) * 100)&lt;br /&gt;
    Copy-Item $datei.FullName -Destination &amp;quot;C:\Ziel&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Move-Item ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Datei verschieben&lt;br /&gt;
Move-Item -Path &amp;quot;C:\Quelle\datei.txt&amp;quot; -Destination &amp;quot;C:\Ziel\datei.txt&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Datei verschieben und umbenennen&lt;br /&gt;
Move-Item -Path &amp;quot;C:\Quelle\alt.txt&amp;quot; -Destination &amp;quot;C:\Ziel\neu.txt&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Ordner verschieben&lt;br /&gt;
Move-Item -Path &amp;quot;C:\Quelle\Ordner&amp;quot; -Destination &amp;quot;C:\Ziel\Ordner&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Mehrere Dateien&lt;br /&gt;
Get-ChildItem &amp;quot;C:\Quelle\*.tmp&amp;quot; | Move-Item -Destination &amp;quot;C:\Temp\&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Mit Überschreiben&lt;br /&gt;
Move-Item -Path &amp;quot;C:\Quelle\datei.txt&amp;quot; -Destination &amp;quot;C:\Ziel\&amp;quot; -Force&lt;br /&gt;
&lt;br /&gt;
# Dateien organisieren nach Erweiterung&lt;br /&gt;
Get-ChildItem &amp;quot;C:\Downloads&amp;quot; -File | ForEach-Object {&lt;br /&gt;
    $erweiterung = $_.Extension.TrimStart(&amp;#039;.&amp;#039;)&lt;br /&gt;
    if (-not $erweiterung) { $erweiterung = &amp;quot;Ohne_Erweiterung&amp;quot; }&lt;br /&gt;
    &lt;br /&gt;
    $zielOrdner = &amp;quot;C:\Downloads\$erweiterung&amp;quot;&lt;br /&gt;
    if (-not (Test-Path $zielOrdner)) {&lt;br /&gt;
        New-Item -Path $zielOrdner -ItemType Directory | Out-Null&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    Move-Item $_.FullName -Destination $zielOrdner&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rename-Item ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Datei umbenennen&lt;br /&gt;
Rename-Item -Path &amp;quot;C:\Temp\alt.txt&amp;quot; -NewName &amp;quot;neu.txt&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Ordner umbenennen&lt;br /&gt;
Rename-Item -Path &amp;quot;C:\Temp\AlterName&amp;quot; -NewName &amp;quot;NeuerName&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Mehrere Dateien umbenennen&lt;br /&gt;
Get-ChildItem &amp;quot;C:\Temp\*.txt&amp;quot; | ForEach-Object {&lt;br /&gt;
    $neuerName = $_.Name -replace &amp;quot;alt&amp;quot;, &amp;quot;neu&amp;quot;&lt;br /&gt;
    Rename-Item -Path $_.FullName -NewName $neuerName&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Nummerierung hinzufügen&lt;br /&gt;
$zaehler = 1&lt;br /&gt;
Get-ChildItem &amp;quot;C:\Bilder\*.jpg&amp;quot; | ForEach-Object {&lt;br /&gt;
    $neuerName = &amp;quot;Bild_$(&amp;#039;{0:D3}&amp;#039; -f $zaehler).jpg&amp;quot;&lt;br /&gt;
    Rename-Item -Path $_.FullName -NewName $neuerName&lt;br /&gt;
    $zaehler++&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Prefix hinzufügen&lt;br /&gt;
Get-ChildItem &amp;quot;C:\Dokumente\*.docx&amp;quot; | ForEach-Object {&lt;br /&gt;
    Rename-Item -Path $_.FullName -NewName &amp;quot;2025_$($_.Name)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Ersetzen mit Regex&lt;br /&gt;
Get-ChildItem &amp;quot;C:\Temp&amp;quot; | Where-Object { $_.Name -match &amp;quot;\d{8}&amp;quot; } | ForEach-Object {&lt;br /&gt;
    $neuerName = $_.Name -replace &amp;quot;\d{8}&amp;quot;, (Get-Date -Format &amp;quot;yyyyMMdd&amp;quot;)&lt;br /&gt;
    Rename-Item -Path $_.FullName -NewName $neuerName&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Modul 7.4: Dateiinhalte lesen ==&lt;br /&gt;
&lt;br /&gt;
=== Get-Content ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Gesamten Inhalt lesen&lt;br /&gt;
$inhalt = Get-Content -Path &amp;quot;C:\Temp\datei.txt&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Zeile für Zeile verarbeiten&lt;br /&gt;
Get-Content -Path &amp;quot;C:\Temp\log.txt&amp;quot; | ForEach-Object {&lt;br /&gt;
    Write-Host &amp;quot;Zeile: $_&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Erste N Zeilen&lt;br /&gt;
Get-Content -Path &amp;quot;C:\Temp\datei.txt&amp;quot; -TotalCount 10&lt;br /&gt;
Get-Content -Path &amp;quot;C:\Temp\datei.txt&amp;quot; -Head 10  # Alias&lt;br /&gt;
&lt;br /&gt;
# Letzte N Zeilen&lt;br /&gt;
Get-Content -Path &amp;quot;C:\Temp\log.txt&amp;quot; -Tail 20&lt;br /&gt;
&lt;br /&gt;
# Mit Encoding&lt;br /&gt;
Get-Content -Path &amp;quot;C:\Temp\utf8.txt&amp;quot; -Encoding UTF8&lt;br /&gt;
Get-Content -Path &amp;quot;C:\Temp\unicode.txt&amp;quot; -Encoding Unicode&lt;br /&gt;
&lt;br /&gt;
# Als Byte-Array lesen&lt;br /&gt;
$bytes = Get-Content -Path &amp;quot;C:\Temp\bild.jpg&amp;quot; -Encoding Byte&lt;br /&gt;
&lt;br /&gt;
# Raw - als einzelner String statt Array&lt;br /&gt;
$text = Get-Content -Path &amp;quot;C:\Temp\datei.txt&amp;quot; -Raw&lt;br /&gt;
&lt;br /&gt;
# Datei überwachen (wie tail -f)&lt;br /&gt;
Get-Content -Path &amp;quot;C:\Logs\app.log&amp;quot; -Wait -Tail 10&lt;br /&gt;
&lt;br /&gt;
# Stream-Reading für große Dateien&lt;br /&gt;
$reader = [System.IO.File]::OpenText(&amp;quot;C:\Temp\gross.txt&amp;quot;)&lt;br /&gt;
while ($null -ne ($zeile = $reader.ReadLine())) {&lt;br /&gt;
    # Zeile verarbeiten&lt;br /&gt;
    if ($zeile -match &amp;quot;ERROR&amp;quot;) {&lt;br /&gt;
        Write-Host $zeile -ForegroundColor Red&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$reader.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Spezielle Dateiformate ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# CSV lesen&lt;br /&gt;
$csv = Import-Csv -Path &amp;quot;C:\Daten\benutzer.csv&amp;quot;&lt;br /&gt;
$csv | ForEach-Object {&lt;br /&gt;
    Write-Host &amp;quot;$($_.Name): $($_.Email)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# CSV mit Delimiter&lt;br /&gt;
$csv = Import-Csv -Path &amp;quot;C:\Daten\export.csv&amp;quot; -Delimiter &amp;quot;;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# JSON lesen&lt;br /&gt;
$json = Get-Content &amp;quot;C:\Daten\config.json&amp;quot; -Raw | ConvertFrom-Json&lt;br /&gt;
Write-Host &amp;quot;Setting: $($json.Settings.MaxConnections)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# XML lesen&lt;br /&gt;
[xml]$xml = Get-Content &amp;quot;C:\Daten\config.xml&amp;quot;&lt;br /&gt;
$xml.Configuration.AppSettings.Add | ForEach-Object {&lt;br /&gt;
    Write-Host &amp;quot;$($_.key) = $($_.value)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# CliXml (PowerShell-spezifisch)&lt;br /&gt;
$objekt = Import-Clixml -Path &amp;quot;C:\Daten\objekt.xml&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Textsuche in Dateien ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Select-String (wie grep)&lt;br /&gt;
Select-String -Path &amp;quot;C:\Logs\*.log&amp;quot; -Pattern &amp;quot;ERROR&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Mit Kontext (Zeilen davor/danach)&lt;br /&gt;
Select-String -Path &amp;quot;C:\Logs\app.log&amp;quot; -Pattern &amp;quot;Exception&amp;quot; -Context 2,5&lt;br /&gt;
&lt;br /&gt;
# Mehrere Pattern&lt;br /&gt;
Select-String -Path &amp;quot;C:\Logs\*.log&amp;quot; -Pattern &amp;quot;ERROR&amp;quot;, &amp;quot;WARNING&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Case-Sensitive&lt;br /&gt;
Select-String -Path &amp;quot;C:\Logs\app.log&amp;quot; -Pattern &amp;quot;Error&amp;quot; -CaseSensitive&lt;br /&gt;
&lt;br /&gt;
# Rekursiv durch Verzeichnisse&lt;br /&gt;
Get-ChildItem -Path &amp;quot;C:\Projekte&amp;quot; -Recurse -Filter &amp;quot;*.cs&amp;quot; | &lt;br /&gt;
    Select-String -Pattern &amp;quot;TODO&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Nur Dateinamen ohne Matches&lt;br /&gt;
Select-String -Path &amp;quot;C:\Logs\*.log&amp;quot; -Pattern &amp;quot;ERROR&amp;quot; -List&lt;br /&gt;
&lt;br /&gt;
# Mit Regex&lt;br /&gt;
Select-String -Path &amp;quot;C:\Logs\app.log&amp;quot; -Pattern &amp;quot;\d{4}-\d{2}-\d{2}&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Negation (nicht enthält)&lt;br /&gt;
Get-Content &amp;quot;C:\Temp\datei.txt&amp;quot; | Where-Object { $_ -notmatch &amp;quot;test&amp;quot; }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Modul 7.5: Dateiinhalte schreiben ==&lt;br /&gt;
&lt;br /&gt;
=== Set-Content und Add-Content ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Inhalt schreiben (überschreibt)&lt;br /&gt;
Set-Content -Path &amp;quot;C:\Temp\ausgabe.txt&amp;quot; -Value &amp;quot;Hallo Welt&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Mehrere Zeilen&lt;br /&gt;
$zeilen = @(&lt;br /&gt;
    &amp;quot;Zeile 1&amp;quot;&lt;br /&gt;
    &amp;quot;Zeile 2&amp;quot;&lt;br /&gt;
    &amp;quot;Zeile 3&amp;quot;&lt;br /&gt;
)&lt;br /&gt;
Set-Content -Path &amp;quot;C:\Temp\zeilen.txt&amp;quot; -Value $zeilen&lt;br /&gt;
&lt;br /&gt;
# Inhalt anhängen (append)&lt;br /&gt;
Add-Content -Path &amp;quot;C:\Temp\log.txt&amp;quot; -Value &amp;quot;$(Get-Date): Neue Zeile&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Aus Pipeline&lt;br /&gt;
Get-Process | Select-Object Name, CPU | Out-File &amp;quot;C:\Temp\prozesse.txt&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Mit Encoding&lt;br /&gt;
Set-Content -Path &amp;quot;C:\Temp\utf8.txt&amp;quot; -Value &amp;quot;Umlaute: äöü&amp;quot; -Encoding UTF8&lt;br /&gt;
&lt;br /&gt;
# Out-File vs Set-Content&lt;br /&gt;
Get-Service | Out-File &amp;quot;C:\Temp\dienste.txt&amp;quot;  # Formatiert&lt;br /&gt;
Get-Service | Set-Content &amp;quot;C:\Temp\dienste2.txt&amp;quot;  # Nur .ToString()&lt;br /&gt;
&lt;br /&gt;
# Append mit Out-File&lt;br /&gt;
Get-Date | Out-File &amp;quot;C:\Temp\log.txt&amp;quot; -Append&lt;br /&gt;
&lt;br /&gt;
# Ohne Zeilenumbruch&lt;br /&gt;
Set-Content -Path &amp;quot;C:\Temp\test.txt&amp;quot; -Value &amp;quot;Text&amp;quot; -NoNewline&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fortgeschrittenes Schreiben ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Stream-Writing für Performance&lt;br /&gt;
$writer = [System.IO.StreamWriter]::new(&amp;quot;C:\Temp\gross.txt&amp;quot;)&lt;br /&gt;
try {&lt;br /&gt;
    1..1000000 | ForEach-Object {&lt;br /&gt;
        $writer.WriteLine(&amp;quot;Zeile $_&amp;quot;)&lt;br /&gt;
    }&lt;br /&gt;
} finally {&lt;br /&gt;
    $writer.Close()&lt;br /&gt;
    $writer.Dispose()&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Binäre Daten schreiben&lt;br /&gt;
$bytes = [byte[]](0..255)&lt;br /&gt;
[System.IO.File]::WriteAllBytes(&amp;quot;C:\Temp\bytes.dat&amp;quot;, $bytes)&lt;br /&gt;
&lt;br /&gt;
# CSV exportieren&lt;br /&gt;
$daten = @(&lt;br /&gt;
    [PSCustomObject]@{Name=&amp;quot;Anna&amp;quot;; Alter=28; Stadt=&amp;quot;Wien&amp;quot;}&lt;br /&gt;
    [PSCustomObject]@{Name=&amp;quot;Bob&amp;quot;; Alter=35; Stadt=&amp;quot;Berlin&amp;quot;}&lt;br /&gt;
)&lt;br /&gt;
$daten | Export-Csv -Path &amp;quot;C:\Temp\personen.csv&amp;quot; -NoTypeInformation&lt;br /&gt;
&lt;br /&gt;
# JSON exportieren&lt;br /&gt;
$config = @{&lt;br /&gt;
    Server = &amp;quot;localhost&amp;quot;&lt;br /&gt;
    Port = 8080&lt;br /&gt;
    SSL = $true&lt;br /&gt;
}&lt;br /&gt;
$config | ConvertTo-Json | Out-File &amp;quot;C:\Temp\config.json&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# XML exportieren&lt;br /&gt;
$daten | Export-Clixml -Path &amp;quot;C:\Temp\daten.xml&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Log-Dateien schreiben ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
function Write-LogFile {&lt;br /&gt;
    param(&lt;br /&gt;
        [string]$nachricht,&lt;br /&gt;
        [string]$pfad = &amp;quot;C:\Logs\script.log&amp;quot;,&lt;br /&gt;
        [ValidateSet(&amp;quot;INFO&amp;quot;, &amp;quot;WARNING&amp;quot;, &amp;quot;ERROR&amp;quot;)]&lt;br /&gt;
        [string]$level = &amp;quot;INFO&amp;quot;&lt;br /&gt;
    )&lt;br /&gt;
    &lt;br /&gt;
    # Ordner erstellen falls nötig&lt;br /&gt;
    $logDir = Split-Path $pfad -Parent&lt;br /&gt;
    if (-not (Test-Path $logDir)) {&lt;br /&gt;
        New-Item -Path $logDir -ItemType Directory -Force | Out-Null&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    # Log-Eintrag&lt;br /&gt;
    $zeitstempel = Get-Date -Format &amp;quot;yyyy-MM-dd HH:mm:ss.fff&amp;quot;&lt;br /&gt;
    $eintrag = &amp;quot;[$zeitstempel] [$level] $nachricht&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Thread-sicher schreiben&lt;br /&gt;
    $mutex = New-Object System.Threading.Mutex($false, &amp;quot;LogFileMutex&amp;quot;)&lt;br /&gt;
    try {&lt;br /&gt;
        $mutex.WaitOne() | Out-Null&lt;br /&gt;
        Add-Content -Path $pfad -Value $eintrag&lt;br /&gt;
    } finally {&lt;br /&gt;
        $mutex.ReleaseMutex()&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Verwendung&lt;br /&gt;
Write-LogFile &amp;quot;Anwendung gestartet&amp;quot; -level &amp;quot;INFO&amp;quot;&lt;br /&gt;
Write-LogFile &amp;quot;Warnung: Speicher knapp&amp;quot; -level &amp;quot;WARNING&amp;quot;&lt;br /&gt;
Write-LogFile &amp;quot;Kritischer Fehler!&amp;quot; -level &amp;quot;ERROR&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Modul 7.6: Pfade manipulieren ==&lt;br /&gt;
&lt;br /&gt;
=== Join-Path ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Pfade kombinieren&lt;br /&gt;
$basis = &amp;quot;C:\Projekte&amp;quot;&lt;br /&gt;
$unter = &amp;quot;MeinProjekt&amp;quot;&lt;br /&gt;
$pfad = Join-Path -Path $basis -ChildPath $unter&lt;br /&gt;
# Ergebnis: C:\Projekte\MeinProjekt&lt;br /&gt;
&lt;br /&gt;
# Mehrere Teile&lt;br /&gt;
$pfad = Join-Path &amp;quot;C:\Projekte&amp;quot; &amp;quot;MeinProjekt&amp;quot; &amp;quot;src&amp;quot; &amp;quot;main.cs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Mit Variablen&lt;br /&gt;
$root = &amp;quot;C:\Daten&amp;quot;&lt;br /&gt;
$jahr = &amp;quot;2025&amp;quot;&lt;br /&gt;
$monat = &amp;quot;01&amp;quot;&lt;br /&gt;
$pfad = Join-Path $root $jahr | Join-Path -ChildPath $monat&lt;br /&gt;
&lt;br /&gt;
# Plattform-unabhängig (verwendet korrekten Separator)&lt;br /&gt;
Join-Path &amp;quot;/home&amp;quot; &amp;quot;user&amp;quot; &amp;quot;documents&amp;quot;  # Linux: /home/user/documents&lt;br /&gt;
Join-Path &amp;quot;C:&amp;quot; &amp;quot;Users&amp;quot; &amp;quot;Documents&amp;quot;    # Windows: C:\Users\Documents&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Split-Path ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$pfad = &amp;quot;C:\Projekte\MeinProjekt\src\main.cs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Eltern-Verzeichnis&lt;br /&gt;
Split-Path -Path $pfad -Parent&lt;br /&gt;
# Ergebnis: C:\Projekte\MeinProjekt\src&lt;br /&gt;
&lt;br /&gt;
# Dateiname&lt;br /&gt;
Split-Path -Path $pfad -Leaf&lt;br /&gt;
# Ergebnis: main.cs&lt;br /&gt;
&lt;br /&gt;
# Nur Extension&lt;br /&gt;
Split-Path -Path $pfad -Extension&lt;br /&gt;
# Ergebnis: .cs&lt;br /&gt;
&lt;br /&gt;
# Laufwerk&lt;br /&gt;
Split-Path -Path $pfad -Qualifier&lt;br /&gt;
# Ergebnis: C:&lt;br /&gt;
&lt;br /&gt;
# Ohne Laufwerk&lt;br /&gt;
Split-Path -Path $pfad -NoQualifier&lt;br /&gt;
# Ergebnis: \Projekte\MeinProjekt\src\main.cs&lt;br /&gt;
&lt;br /&gt;
# Prüfen ob Pfad gültig&lt;br /&gt;
Split-Path -Path $pfad -IsAbsolute&lt;br /&gt;
# Ergebnis: True&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Test-Path ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Existiert Pfad?&lt;br /&gt;
Test-Path &amp;quot;C:\Windows&amp;quot;  # True&lt;br /&gt;
Test-Path &amp;quot;C:\GibtEsNicht&amp;quot;  # False&lt;br /&gt;
&lt;br /&gt;
# Ist es ein Container (Ordner)?&lt;br /&gt;
Test-Path &amp;quot;C:\Windows&amp;quot; -PathType Container  # True&lt;br /&gt;
Test-Path &amp;quot;C:\Windows\notepad.exe&amp;quot; -PathType Container  # False&lt;br /&gt;
&lt;br /&gt;
# Ist es eine Datei?&lt;br /&gt;
Test-Path &amp;quot;C:\Windows\notepad.exe&amp;quot; -PathType Leaf  # True&lt;br /&gt;
&lt;br /&gt;
# Mit Wildcards&lt;br /&gt;
Test-Path &amp;quot;C:\Windows\*.exe&amp;quot;  # True wenn .exe vorhanden&lt;br /&gt;
&lt;br /&gt;
# Ist Pfad gültig (nicht ob existent)?&lt;br /&gt;
Test-Path &amp;quot;C:\&amp;lt;&amp;gt;invalid&amp;quot; -IsValid  # False&lt;br /&gt;
&lt;br /&gt;
# Neuere als Datum&lt;br /&gt;
Test-Path &amp;quot;C:\Temp\*.txt&amp;quot; | Where-Object {&lt;br /&gt;
    (Get-Item $_).LastWriteTime -gt (Get-Date).AddDays(-7)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Resolve-Path und Convert-Path ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Relativen Pfad auflösen&lt;br /&gt;
Set-Location &amp;quot;C:\Windows&amp;quot;&lt;br /&gt;
Resolve-Path &amp;quot;.\System32&amp;quot;&lt;br /&gt;
# Ergebnis: C:\Windows\System32&lt;br /&gt;
&lt;br /&gt;
# Mit Wildcards - alle passenden Pfade&lt;br /&gt;
Resolve-Path &amp;quot;C:\Windows\*.exe&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Convert-Path - nur String&lt;br /&gt;
Convert-Path &amp;quot;.\System32&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Absolute Pfade erstellen&lt;br /&gt;
$relativerPfad = &amp;quot;..\..\Projekte&amp;quot;&lt;br /&gt;
$absoluterPfad = Resolve-Path $relativerPfad&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [System.IO.Path] Klasse ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Dateiname ohne Extension&lt;br /&gt;
[System.IO.Path]::GetFileNameWithoutExtension(&amp;quot;C:\Temp\test.txt&amp;quot;)&lt;br /&gt;
# Ergebnis: test&lt;br /&gt;
&lt;br /&gt;
# Extension&lt;br /&gt;
[System.IO.Path]::GetExtension(&amp;quot;C:\Temp\test.txt&amp;quot;)&lt;br /&gt;
# Ergebnis: .txt&lt;br /&gt;
&lt;br /&gt;
# Verzeichnisname&lt;br /&gt;
[System.IO.Path]::GetDirectoryName(&amp;quot;C:\Temp\test.txt&amp;quot;)&lt;br /&gt;
# Ergebnis: C:\Temp&lt;br /&gt;
&lt;br /&gt;
# Dateiname&lt;br /&gt;
[System.IO.Path]::GetFileName(&amp;quot;C:\Temp\test.txt&amp;quot;)&lt;br /&gt;
# Ergebnis: test.txt&lt;br /&gt;
&lt;br /&gt;
# Temp-Pfad&lt;br /&gt;
[System.IO.Path]::GetTempPath()&lt;br /&gt;
# Ergebnis: C:\Users\...\AppData\Local\Temp\&lt;br /&gt;
&lt;br /&gt;
# Temp-Dateiname&lt;br /&gt;
[System.IO.Path]::GetTempFileName()&lt;br /&gt;
&lt;br /&gt;
# Zufälliger Dateiname&lt;br /&gt;
[System.IO.Path]::GetRandomFileName()&lt;br /&gt;
&lt;br /&gt;
# Pfad kombinieren&lt;br /&gt;
[System.IO.Path]::Combine(&amp;quot;C:\Projekte&amp;quot;, &amp;quot;MeinProjekt&amp;quot;, &amp;quot;src&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Ungültige Zeichen&lt;br /&gt;
[System.IO.Path]::GetInvalidFileNameChars()&lt;br /&gt;
[System.IO.Path]::GetInvalidPathChars()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Modul 7.7: Dateieigenschaften und Attribute ==&lt;br /&gt;
&lt;br /&gt;
=== Get-Item und Get-ItemProperty ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Datei-Objekt abrufen&lt;br /&gt;
$datei = Get-Item &amp;quot;C:\Temp\test.txt&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Eigenschaften&lt;br /&gt;
$datei.Name              # Dateiname&lt;br /&gt;
$datei.FullName          # Vollständiger Pfad&lt;br /&gt;
$datei.Length            # Größe in Bytes&lt;br /&gt;
$datei.Extension         # .txt&lt;br /&gt;
$datei.Directory         # Verzeichnis-Objekt&lt;br /&gt;
$datei.DirectoryName     # Verzeichnis-Pfad&lt;br /&gt;
$datei.CreationTime      # Erstellungsdatum&lt;br /&gt;
$datei.LastWriteTime     # Letzte Änderung&lt;br /&gt;
$datei.LastAccessTime    # Letzter Zugriff&lt;br /&gt;
$datei.Attributes        # Attribute (ReadOnly, Hidden, etc.)&lt;br /&gt;
$datei.IsReadOnly        # Boolean&lt;br /&gt;
&lt;br /&gt;
# Alle Eigenschaften anzeigen&lt;br /&gt;
$datei | Format-List *&lt;br /&gt;
&lt;br /&gt;
# Spezifische Eigenschaft&lt;br /&gt;
Get-ItemProperty &amp;quot;C:\Temp\test.txt&amp;quot; -Name Length&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Attribute setzen ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Datei-Attribute&lt;br /&gt;
$datei = Get-Item &amp;quot;C:\Temp\test.txt&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# ReadOnly setzen&lt;br /&gt;
$datei.IsReadOnly = $true&lt;br /&gt;
&lt;br /&gt;
# Oder mit Set-ItemProperty&lt;br /&gt;
Set-ItemProperty &amp;quot;C:\Temp\test.txt&amp;quot; -Name IsReadOnly -Value $true&lt;br /&gt;
&lt;br /&gt;
# Hidden setzen&lt;br /&gt;
$datei.Attributes = $datei.Attributes -bor [System.IO.FileAttributes]::Hidden&lt;br /&gt;
&lt;br /&gt;
# Attribute entfernen&lt;br /&gt;
$datei.Attributes = $datei.Attributes -band (-bnot [System.IO.FileAttributes]::Hidden)&lt;br /&gt;
&lt;br /&gt;
# Mehrere Attribute&lt;br /&gt;
$datei.Attributes = [System.IO.FileAttributes]::ReadOnly -bor [System.IO.FileAttributes]::Hidden&lt;br /&gt;
&lt;br /&gt;
# Zeitstempel ändern&lt;br /&gt;
$datei.CreationTime = Get-Date &amp;quot;2025-01-01&amp;quot;&lt;br /&gt;
$datei.LastWriteTime = Get-Date &amp;quot;2025-01-15&amp;quot;&lt;br /&gt;
$datei.LastAccessTime = Get-Date&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dateigrößen und Statistiken ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Größe einer Datei&lt;br /&gt;
$datei = Get-Item &amp;quot;C:\Temp\gross.zip&amp;quot;&lt;br /&gt;
$groesseMB = [math]::Round($datei.Length / 1MB, 2)&lt;br /&gt;
Write-Host &amp;quot;Größe: $groesseMB MB&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Gesamtgröße eines Ordners&lt;br /&gt;
$ordnerGroesse = Get-ChildItem &amp;quot;C:\Temp&amp;quot; -Recurse -File | &lt;br /&gt;
    Measure-Object -Property Length -Sum&lt;br /&gt;
$groesseGB = [math]::Round($ordnerGroesse.Sum / 1GB, 2)&lt;br /&gt;
Write-Host &amp;quot;Ordner-Größe: $groesseGB GB&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Top 10 größte Dateien&lt;br /&gt;
Get-ChildItem &amp;quot;C:\Users&amp;quot; -Recurse -File -ErrorAction SilentlyContinue |&lt;br /&gt;
    Sort-Object Length -Descending |&lt;br /&gt;
    Select-Object -First 10 FullName, @{N=&amp;#039;SizeMB&amp;#039;; E={[math]::Round($_.Length/1MB,2)}} |&lt;br /&gt;
    Format-Table -AutoSize&lt;br /&gt;
&lt;br /&gt;
# Dateien nach Alter&lt;br /&gt;
$vor30Tagen = (Get-Date).AddDays(-30)&lt;br /&gt;
Get-ChildItem &amp;quot;C:\Temp&amp;quot; -File | &lt;br /&gt;
    Where-Object { $_.LastWriteTime -lt $vor30Tagen } |&lt;br /&gt;
    Select-Object Name, LastWriteTime&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Modul 7.8: Berechtigungen und ACLs ==&lt;/div&gt;</summary>
		<author><name>Gerhard</name></author>
	</entry>
</feed>