Archive for the ‘Powershell’ Category.
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-26, 22:54
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
Category:
Powershell,
SQL |
Kommentare deaktiviert für Powershell und SQL – INSERT
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-12-18, 11:02
Heute habe ich mir mal die iTextsharp.dll von Sourceforge geladen, um aus C# heraus mal eine PDF Datei zu erzeugen. Im Visual Studio Projekt muss dann nur ein Verweis auf diese DLL erstellt werden, dann sollte das folgende Beispiel problemlos laufen. Ausgehend von diesem Beispiel werde ich mal schauen, ob man das nicht für was Sinnvolles einsetzen kann.
Ist sicher kein Ersatz für LaTeX, ein paar Dinge könnte ich mir jedoch vorstellen… 🙂
using System.IO;
using System.Text;
using iTextSharp.text;
using iTextSharp.text.pdf;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Document pdfDocument = new Document();
PdfWriter.GetInstance(pdfDocument, new FileStream("C:\\hallo.PDF", FileMode.Create));
pdfDocument.Open();
pdfDocument.Add(new Paragraph("Ich bin ein Absatz"));
pdfDocument.Close();
}
}
} |
using System.IO;
using System.Text;
using iTextSharp.text;
using iTextSharp.text.pdf;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Document pdfDocument = new Document();
PdfWriter.GetInstance(pdfDocument, new FileStream("C:\\hallo.PDF", FileMode.Create));
pdfDocument.Open();
pdfDocument.Add(new Paragraph("Ich bin ein Absatz"));
pdfDocument.Close();
}
}
}
Auch aus Powershell heraus lässt sich iTextsharp nutzen: http://www.powershell.nu/2009/09/08/scripting-pdf-documents-through-powershell/
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-08-15, 13:09
Folgendes Skript listet nur einen Unterordner ausgehend vom aktuellen auf:
gci -recurse | ? {$_.PSisContainer -eq $true} |where{
if(
($_.fullname.split("\")).count -le 4){write-host $_.fullname}
} |
gci -recurse | ? {$_.PSisContainer -eq $true} |where{
if(
($_.fullname.split("\")).count -le 4){write-host $_.fullname}
}
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
Category:
Powershell |
Kommentare deaktiviert für Powershell: Ordner bis zu bestimmter Tiefe auflisten
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