Mit diesem Code können Ordnerstrukturen des Filesystems in eine Textdatei exportiert werden. Es wird der Startordner sowie der Pfad und der Dateiname der Exportdatei angegeben werden. Nach der Erstellung kann direkt die Textdatei geöffnet werden.
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") $objForm = New-Object System.Windows.Forms.Form $objForm.Text = "FolderListGenerator" $objForm.Size = New-Object System.Drawing.Size(300,200) $objForm.StartPosition = "CenterScreen" $objForm.KeyPreview = $True $objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter") { $path=$objTextBox.Text;$objForm.Close()} }) $objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape") { $objForm.Close()} }) $OKButton = New-Object System.Windows.Forms.Button $OKButton.Location = New-Object System.Drawing.Size(75,120) $OKButton.Size = New-Object System.Drawing.Size(75,23) $OKButton.Text = "OK" $OKButton.Add_Click({$path=$objTextBox1.Text;$file=$objTextBox2.Text;$objForm.Close()}) $objForm.Controls.Add($OKButton) $CancelButton = New-Object System.Windows.Forms.Button $CancelButton.Location = New-Object System.Drawing.Size(150,120) $CancelButton.Size = New-Object System.Drawing.Size(75,23) $CancelButton.Text = "Cancel" $CancelButton.Add_Click({$objForm.Close()}) $objForm.Controls.Add($CancelButton) $objLabel1 = New-Object System.Windows.Forms.Label $objLabel1.Location = New-Object System.Drawing.Size(10,20) $objLabel1.Size = New-Object System.Drawing.Size(280,20) $objLabel1.Text = "Bitte Verzeichnispfad eingeben (z.B. C:\Folder):" $objForm.Controls.Add($objLabel1) $objTextBox1 = New-Object System.Windows.Forms.TextBox $objTextBox1.Location = New-Object System.Drawing.Size(10,40) $objTextBox1.Size = New-Object System.Drawing.Size(260,20) $objTextBox1.Text = "" $objForm.Controls.Add($objTextBox1) $objLabel2 = New-Object System.Windows.Forms.Label $objLabel2.Location = New-Object System.Drawing.Size(10,70) $objLabel2.Size = New-Object System.Drawing.Size(280,20) $objLabel2.Text = "Bitte Dateiablage eingeben (z.B. C:\temp\folder.txt):" $objForm.Controls.Add($objLabel2) $objTextBox2 = New-Object System.Windows.Forms.TextBox $objTextBox2.Location = New-Object System.Drawing.Size(10,90) $objTextBox2.Size = New-Object System.Drawing.Size(260,20) $objTextBox2.Text = "" $objForm.Controls.Add($objTextBox2) [void] $objForm.ShowDialog() Get-Childitem $objTextBox1.Text -recurse -filter * | ? { $_.PSisContainer -eq $true} | % {$_.fullname -replace "\\","`t" } | sort | out-file $objTextBox2.Text $a = new-object -comobject wscript.shell $intAnswer = $a.popup("Exportdatei öffnen?",0,"FolderListGenerator",4) If ($intAnswer -eq 6) { Invoke-Item $file } else { $a.popup("Datei erstellt") }
Als Trennzeichen wird der TAB genutzt, so dass ein Import z.B. in Excel ohne Probleme funktionieren sollte.
Fehler:
Out-File : Das Argument kann nicht an den Parameter „FilePath“ gebunden werden, da es NULL ist.
In Zeile:4 Zeichen:17
+ sort | out-file $file
+ ~~~~~
+ CategoryInfo : InvalidData: (:) [Out-File], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.OutFileComm
and
Hallo Herr Engelke,
da ist leider ein Fehler im Skript aufgetreten.
Ich habe den Block Zeile 53-56 im Artikel angepasst.
Der Artikel stammt allerdings von 2013 und ich muss gestehen, dass ich das ganze heutzutage völlig anders aufziehen würde.
Da ich nicht weiß, wie dringend bei Ihnen die Umsetzung für Sie ist:
Aufgrund ihrers Anstoßes habe ich überlegt einen neuen Artikel am Wochenende zu erstellen, der die Anforderung deutlich besser umsetzt.
vielen Dank, das hat funktioniert!
Wir müssen Dokumentationen erstellen über Controlled Folder Access auf unseren Fileservern, dafür ist dieses Tool sicher hilfreich.
Aktualisierungen/Verbesserungen sind daher willkommen..Danke im Voraus!