Powershell Template Engine

A template engine that allows you to have powershell expressions in your templates is a very powerful thing: http://weblogs.asp.net/soever/archive/2006/12/31/a-templating-engine-using-powershell-expressions.aspx Example Input: Multi Line Expression:[[ get-date1..20]] Define function [[ function get-theanswer {42;} ]] Single Line: [[ theanswer ]] EOF Example Output: Multi Line Expression:03/14/2007 22:38:09 1 2 3 4 5 6 7 8 9 10 11…

0

get-SHA256

Get the SHA256 hash in one line of powershell: function get-sha256 {param($file);[system.bitconverter]::tostring([System.Security.Cryptography.sha256]::create().computehash([system.io.file]::openread((resolve-path $file)))) -replace “-“,””}

1

get-datatable.ps1

get-datatable.ps1 is an improvement on the get-dataset.ps1 from an earlier post. Instead of returning a dataset it returns a DataTable; and a UpdateSql method is added to the object returned, so you don’t need a separate script to send the changes back to sql. This allows updates to a small table to look like: $t =…

0

Managing Performance Counters via Command Line

When it comes to scripting the setup of performance counters Logman is your friend; and Relog comes in really handy for converting a binary log to SQL log.

0

Windows Automated Installation Kit (AIK)

It’s great to see powerful tools be made publicly available; winpe and imagex are powerful tools I’ve been using for some time to deploy systems and recover from hardware & software failures. Windows Automated Installation Kit (AIK) Overview The Windows Automated Installation Kit (Windows AIK) is designed to help corporate IT professionals customize and deploy the…

1

Updating a DataSet with Powershell and saving changes back to SQL

This example uses the AdventureWorks sample database. # get the dataset PS C:\demo> $ds = .\get-dataset.ps1 “select * from Production.ProductModel” -db adventureworks # write out xml from the instructions column into seperate files PS C:\demo> $ds.Tables[0] | ?{$_[“instructions”] -ne [dbnull]::value } | %{$_[“instructions”]| sc “productmodel-$($_[‘productmodelid’]).xml”} # verify output PS C:\demo> ls productmodel-* Directory: Microsoft.PowerShell.Core\FileSystem::C:\demo Mode…

1

Capturing SQL Generated by SMO in Powershell

The following example uses the get-sqlserver.ps1 script in my search path. get-sqlserver.ps1: param ($server=”.”) $null = [reflection.assembly]::loadwithpartialname(“microsoft.sqlserver.smo”) new-object Microsoft.SqlServer.Management.Smo.Server $server; This example will shows how to use SMO objects to generate a SQL Script that will drop all the rowguid columns from the adventure works database: PS C:\demo> $srv = get-sqlserver PS C:\demo> $db =…

0

EventTriggers

This could be usefull; I always like knowing about obscure commands that are on every box I work with. eventtriggers[.exe] /create [/s Computer [/u Domain\User [/p Password]]] /tr TriggerName [/l [APPLICATION] [SYSTEM] [SECURITY] [“DNS Server”] [LOG] [DirectoryLogName] [*]] {[/eid ID] | [/t {ERROR | INFORMATION | WARNING | SUCCESSAUDIT | FAILUREAUDIT}] | [/so Source]} [/d Description]…

0