This commit is contained in:
Patrick Asmus
2026-06-16 12:33:05 +02:00
parent 5da2cd0e49
commit c8b5b7f347
3 changed files with 193 additions and 18 deletions

118
Get-FileInventory.ps1 Normal file
View File

@@ -0,0 +1,118 @@
# Script Name: Get-FileInventory.ps1
# Beschreibung: Erstellt eine Dateiliste mit Groesse, Erstellungsdatum und letzter Aenderung.
# Autor: Patrick Asmus
# Web: https://www.patrick-asmus.de
# Git-Reposit.: https://git.techniverse.net/scriptos/get-fileinventory.git
# Version: 1.0
# Datum: 16.06.2026
# Modifikation: Initial
#####################################################
param(
[string]$Path,
[string]$OutputDirectory = (Join-Path -Path $PSScriptRoot -ChildPath "exports"),
[switch]$NoExcel
)
# Variablen:
$TargetFolder = "C:\Temp"
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
if (-not $PSBoundParameters.ContainsKey("Path") -or [string]::IsNullOrWhiteSpace($Path)) {
$Path = $TargetFolder
}
function Convert-BytesToReadableSize {
param(
[Parameter(Mandatory = $true)]
[long]$Bytes
)
if ($Bytes -ge 1GB) {
return "{0:N2} GB" -f ($Bytes / 1GB)
}
if ($Bytes -ge 1MB) {
return "{0:N2} MB" -f ($Bytes / 1MB)
}
if ($Bytes -ge 1KB) {
return "{0:N2} KB" -f ($Bytes / 1KB)
}
return "$Bytes B"
}
if (-not (Test-Path -LiteralPath $Path -PathType Container)) {
throw "Der angegebene Ordner wurde nicht gefunden: $Path"
}
$resolvedPath = (Resolve-Path -LiteralPath $Path).Path
if (-not (Test-Path -LiteralPath $OutputDirectory -PathType Container)) {
New-Item -ItemType Directory -Path $OutputDirectory | Out-Null
}
$resolvedOutputDirectory = (Resolve-Path -LiteralPath $OutputDirectory).Path.TrimEnd("\")
$timestamp = Get-Date -Format "yyyyMMdd-HHmmss"
$safeFolderName = (Split-Path -Path $resolvedPath -Leaf)
if ([string]::IsNullOrWhiteSpace($safeFolderName)) {
$safeFolderName = "Laufwerk"
}
$csvPath = Join-Path -Path $OutputDirectory -ChildPath "Dateiliste-$safeFolderName-$timestamp.csv"
$xlsxPath = Join-Path -Path $OutputDirectory -ChildPath "Dateiliste-$safeFolderName-$timestamp.xlsx"
Write-Host "Durchsuche Ordner inklusive Unterordner:" -ForegroundColor Cyan
Write-Host " $resolvedPath"
Write-Host ""
$files = @(Get-ChildItem -LiteralPath $Path -File -Recurse -Force -ErrorAction SilentlyContinue |
Where-Object {
$filePath = $_.FullName
-not (
$filePath.Equals($resolvedOutputDirectory, [System.StringComparison]::InvariantCultureIgnoreCase) -or
$filePath.StartsWith("$resolvedOutputDirectory\", [System.StringComparison]::InvariantCultureIgnoreCase)
)
} |
Sort-Object FullName |
Select-Object `
@{Name = "Dateiname"; Expression = { $_.Name } },
@{Name = "Ordner"; Expression = { $_.DirectoryName } },
@{Name = "VollstaendigerPfad"; Expression = { $_.FullName } },
@{Name = "Endung"; Expression = { $_.Extension } },
@{Name = "GroesseBytes"; Expression = { $_.Length } },
@{Name = "GroesseLesbar"; Expression = { Convert-BytesToReadableSize -Bytes $_.Length } },
@{Name = "ErstelltAm"; Expression = { $_.CreationTime } },
@{Name = "ZuletztGeaendertAm"; Expression = { $_.LastWriteTime } })
if ($files.Count -gt 0) {
$files | Format-Table Dateiname, GroesseLesbar, ErstelltAm, ZuletztGeaendertAm -AutoSize
}
else {
Write-Host "Keine Dateien gefunden." -ForegroundColor Yellow
}
$files | Export-Csv -Path $csvPath -Delimiter ";" -NoTypeInformation -Encoding UTF8
Write-Host ""
Write-Host "CSV exportiert nach:" -ForegroundColor Green
Write-Host " $csvPath"
if (-not $NoExcel) {
$importExcelModule = Get-Module -ListAvailable -Name ImportExcel | Select-Object -First 1
if ($null -ne $importExcelModule) {
$files | Export-Excel -Path $xlsxPath -WorksheetName "Dateiliste" -AutoSize -FreezeTopRow -BoldTopRow
Write-Host "Excel-Datei exportiert nach:" -ForegroundColor Green
Write-Host " $xlsxPath"
}
else {
Write-Host "Excel-XLSX wurde uebersprungen, weil das Modul 'ImportExcel' nicht installiert ist." -ForegroundColor Yellow
Write-Host "Die CSV-Datei kann direkt mit Excel geoeffnet werden."
}
}
Write-Host ""
Write-Host ("Gefundene Dateien: {0}" -f $files.Count) -ForegroundColor Cyan

18
LICENSE
View File

@@ -1,10 +1,7 @@
GNU AFFERO GENERAL PUBLIC LICENSE
Version 3, 19 November 2007
MIT License
---
Copyright ©
Name: Patrick Asmus (scriptos)
Email: support@techniverse.net
Website: https://www.patrick-asmus.de
@@ -12,15 +9,8 @@ Blog: https://www.cleveradmin.de
---
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -4,10 +4,10 @@
</a>
</p>
<h1 align="center">Name des Projekts</h1>
<h1 align="center">Get-FileInventory</h1>
<h4 align="center">
Kurzbeschreibung des Projekts/Anwendung, um die es geht
PowerShell-Script zum Auflisten von Dateigrößen, Erstellungsdatum und Änderungsdatum
</h4>
<h6 align="center">
@@ -21,9 +21,76 @@
</h6>
<br><br>
## Beschreibung
CONTENT BEREICH
`Get-FileInventory.ps1` durchsucht einen Ordner inklusive aller Unterordner und erstellt eine übersichtliche Dateiliste.
Erfasst werden:
- Dateiname
- Ordner
- vollständiger Pfad
- Dateiendung
- Größe in Bytes
- lesbare Größe, zum Beispiel `1,25 MB`
- Erstellungsdatum
- Datum der letzten Änderung
Die Ergebnisse werden im Terminal angezeigt und zusätzlich als CSV-Datei exportiert. Die CSV-Datei kann direkt mit Excel geöffnet werden. Wenn das PowerShell-Modul `ImportExcel` installiert ist, erstellt das Script zusätzlich eine `.xlsx`-Datei.
## Schnellstart
Öffne `Get-FileInventory.ps1` und passe oben diese Variable an:
```powershell
$TargetFolder = "C:\Temp"
```
Danach führst du das Script aus:
```powershell
.\Get-FileInventory.ps1
```
Die Exportdateien werden standardmäßig im Unterordner `exports` gespeichert.
## Nutzung mit Parametern
Du kannst den zu durchsuchenden Ordner auch direkt beim Start übergeben:
```powershell
.\Get-FileInventory.ps1 -Path "C:\Users\patrick.asmus\Documents"
```
Einen anderen Exportordner gibst du so an:
```powershell
.\Get-FileInventory.ps1 -Path "C:\Temp" -OutputDirectory "C:\Temp\Auswertung"
```
Wenn du nur eine CSV-Datei erzeugen möchtest:
```powershell
.\Get-FileInventory.ps1 -Path "C:\Temp" -NoExcel
```
## Optionaler Excel-Export
Für den direkten Export in eine `.xlsx`-Datei wird das Modul `ImportExcel` verwendet. Falls du es installieren möchtest, starte PowerShell und führe aus:
```powershell
Install-Module ImportExcel -Scope CurrentUser
```
Danach erzeugt das Script automatisch zusätzlich zur CSV-Datei auch eine Excel-Datei.
## Hinweise
- Die Suche läuft rekursiv, also inklusive aller Unterordner.
- Versteckte Dateien werden berücksichtigt.
- Ordner, auf die PowerShell keinen Zugriff hat, werden übersprungen.
- Die CSV nutzt ein Semikolon als Trennzeichen, damit sie in einer deutschen Excel-Umgebung sauber in Spalten geöffnet wird.
- Wenn der Exportordner innerhalb des Suchordners liegt, wird er nicht in die Auswertung einbezogen.
<br><br>
<p align="center">
@@ -34,4 +101,4 @@ CONTENT BEREICH
<sub>
© Patrick Asmus · Techniverse Network · <a href="./LICENSE">Lizenz</a>
</sub>
</p>
</p>