2011-06-15, 20:51
Folgendes Skript gibt alle Dateien in eine Datei aus, deren Pfad länger als 240 Zeichen ist.
cd c:\
clear-host
$Host.UI.RawUI.BufferSize = New-Object Management.Automation.Host.Size (600, 25)
gci -Recurse | ? { $_.fullname.length -gt 240} | Select-Object FullName | Out-File "c:\longfilenames-20110614.txt" -Width 350 |
cd c:\
clear-host
$Host.UI.RawUI.BufferSize = New-Object Management.Automation.Host.Size (600, 25)
gci -Recurse | ? { $_.fullname.length -gt 240} | Select-Object FullName | Out-File "c:\longfilenames-20110614.txt" -Width 350
Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined.
Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.
More Posts - Website
Schlagwörter:
Powershell Category:
Powershell |
Kommentare deaktiviert für Powershell: Lange Dateipfade ermitteln
2011-03-19, 17:38
Das folgende Skript sucht rekursiv alle Ordner bis zum zweiten Unterverzeichnis und gibt den kompletten Pfad aus.
&{gci * | ?{$_.psiscontainer}; gci *\* | ?{$_.psiscontainer}; gci *\*\*| ?{$_.psiscontainer}} | Select-Object FullName | sort |
&{gci * | ?{$_.psiscontainer}; gci *\* | ?{$_.psiscontainer}; gci *\*\*| ?{$_.psiscontainer}} | Select-Object FullName | sort
Da die Pfade jedoch recht lang werden können und oft mehr als die 80 Zeichen hatten, muss man die Ausgabebreite anpassen: http://stackoverflow.com/questions/978777/powershell-output-column-width hatte den entsprechenden Hinweis:
clear-host
$Host.UI.RawUI.BufferSize = New-Object Management.Automation.Host.Size (500, 25)
&{gci *\* | ?{$_.psiscontainer};} | Select-Object FullName | sort | Out-File "c:\folders.txt" -Append -Width 250 |
clear-host
$Host.UI.RawUI.BufferSize = New-Object Management.Automation.Host.Size (500, 25)
&{gci *\* | ?{$_.psiscontainer};} | Select-Object FullName | sort | Out-File "c:\folders.txt" -Append -Width 250
Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined.
Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.
More Posts - Website
Schlagwörter:
Powershell Category:
Powershell |
Kommentare deaktiviert für Powershell Skript für gci mit begrenzter Rekursionstiefe
2011-03-19, 17:31
Unter http://technet.microsoft.com/en-us/library/ee692944.aspx findet sich die TechNet Seite von Microsoft zum Thema Powershell. Jede Menge Referenz, Beispiele und Vorlagen.
Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined.
Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.
More Posts - Website
Schlagwörter:
Powershell Category:
Powershell |
Kommentare deaktiviert für Powershell TechNet bei Microsoft
2010-12-25, 10:17
Auf http://richardspowershellblog.wordpress.com/2007/04/19/insert-values-to-a-sql-server-table/ habe ich ein kurzes Statement gefunden, um per Powershell Einträge in einer SQL Datenbank vorzunehmen.
# open connection to the server
$conn = New-Object System.Data.SqlClient.SqlConnection("Data Source=localhost; Initial Catalog=Posh; Integrated Security=SSPI")
$conn.Open()
# create command object
$cmd = $conn.CreateCommand()
# create statement
$cmd.CommandText ="INSERT myTable VALUES ('Hello', 'World', 123)"
# execute command
$cmd.ExecuteNonQuery()
# close connection
$conn.Close() |
# open connection to the server
$conn = New-Object System.Data.SqlClient.SqlConnection("Data Source=localhost; Initial Catalog=Posh; Integrated Security=SSPI")
$conn.Open()
# create command object
$cmd = $conn.CreateCommand()
# create statement
$cmd.CommandText ="INSERT myTable VALUES ('Hello', 'World', 123)"
# execute command
$cmd.ExecuteNonQuery()
# close connection
$conn.Close()
Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined.
Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.
More Posts - Website
2010-09-19, 06:43
Vor einer Weile hatte ich schon einmal beschrieben, wie man mit Powershell und der Taglib Bibliothek auf MP3 Metadaten zugreifen kann (http://uweziegenhagen.de/?p=732). Erneutes Googeln hat heut morgen eine Umsetzung der Bibliothek für C# und Mono gebracht.
Werd mal testen, ob ich das Projekt mit Visual Studio Express 2010 übersetzen kann.
Nachtrag vom 23.09.2010: Übersetzung hat nicht funktioniert, werde wohl weiterhin mit der fertigen DLL arbeiten.
Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined.
Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.
More Posts - Website
2010-05-23, 20:46
Unter http://www.vistax64.com/powershell/190352-executing-sql-queries-powershell.html gibt es einige einfache Skripte für den Abruf von Daten aus einer SQL-Server Datenbank.
Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined.
Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.
More Posts - Website
Schlagwörter:
Powershell Category:
Powershell |
Kommentare deaktiviert für DB-Abfragen mit Powershell
2010-05-23, 20:24
Ausgehend von einer komplexeren Funktion, die mir bereitgestellt wurde, hier ein Beispiel für die Berechnung von MD5-Hashes in Powershell:
[System.IO.FileInfo] $file = "c:\hallo.txt"
$cryptoServiceProvider = [System.Security.Cryptography.MD5CryptoServiceProvider];
$hashAlgorithm = new-object $cryptoServiceProvider
$stream = $file.OpenRead();
$hashByteArray = $hashAlgorithm.ComputeHash($stream);
$stream.Close();
return [string]$hashByteArray; |
[System.IO.FileInfo] $file = "c:\hallo.txt"
$cryptoServiceProvider = [System.Security.Cryptography.MD5CryptoServiceProvider];
$hashAlgorithm = new-object $cryptoServiceProvider
$stream = $file.OpenRead();
$hashByteArray = $hashAlgorithm.ComputeHash($stream);
$stream.Close();
return [string]$hashByteArray;
Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined.
Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.
More Posts - Website
Schlagwörter:
Powershell Category:
Powershell |
Kommentare deaktiviert für MD5-Hash für eine Datei bestimmen
2010-05-09, 09:44
Für eine Liste von Dateien wollte ich wissen, welche der Dateien nicht gefunden werden können. Dank Powershell ist dies einfach zu erledigen.
- Ich importiere die entsprechende CSV-Datei (Hinweis: In der ersten Zeile der zu importierenden Datei steht „file“, über diese Bezeichnung erkennt Powershell die Spalte.
- Für jeden Eintrag in der Liste wird der Pfad überprüft.
- Wenn die der Pfad nicht gefunden wird, wird die entsprechende Pfadangabe an die
notfound.txt
Datei gehangen.
$files = Import-Csv t:\dateipfade.txt
foreach ($i in $files){
if (-not (Test-Path $i.file)) {
$i.file | Out-File "t:\notfound.txt" -append
}
} |
$files = Import-Csv t:\dateipfade.txt
foreach ($i in $files){
if (-not (Test-Path $i.file)) {
$i.file | Out-File "t:\notfound.txt" -append
}
}
Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined.
Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.
More Posts - Website
Schlagwörter:
Powershell Category:
Powershell |
Kommentare deaktiviert für Dateipfade überprüfen mit Powershell
2010-04-10, 10:36
Da der Internet Explorer der Meinung ist, PDF-Dateien im eingebetteten Reader anzuzeigen und das entsprechende PDF die Werkzeugleiste versteckt, brauchte ich ein alternatives Kommando, das die Datei direkt herunterlädt. Auf http://huddledmasses.org/wget-for-powershell/ gab es die Lösung:
$client = new-object System.Net.WebClient
$client.DownloadFile("<URL>","<Dateipfad, in den gespeichert werden soll>") |
$client = new-object System.Net.WebClient
$client.DownloadFile("<URL>","<Dateipfad, in den gespeichert werden soll>")
Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined.
Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.
More Posts - Website
2010-02-15, 13:19
Powerboots (http://huddledmasses.org/powerboots) ist ein .Net GUI Framework für Powershell, mit dem man recht einfach WPF Dialoge und Formulare erstellen kann.
Installation
- Download der ZIP-Datei von http://powerboots.codeplex.com/releases/view/28954
- Entpacken des Ordners in das Powershell Modules Verzeichnis, bei mir (Powershell 2 CTP)
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
get-module -list PowerBoots
sollte jetzt Informationen in einer Liste ausgeben
- Import des Powerboots-Moduls über
Import-Module PowerBoots
(Powershell gibt hier einen Fehler aus, ist aber wohl ein Fehler der POSH 2 CTP Version). Das Modul muss bei jedem Neustart neu geladen werden, daher empfiehlt sich ein Eintrag in der POSH Profile-Datei.
New-BootsWindow { Button "Push Me" }
sollte jetzt ein kleines Fenster mit dem Button zeigen
Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined.
Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.
More Posts - Website
Schlagwörter:
Powershell Category:
Powershell |
Kommentare deaktiviert für Powershell und Powerboots – Teil 1