A blog about SQL Server, SSIS, C# and whatever else I happen to be dealing with in my professional life.

Find ramblings

Thursday, September 10, 2009

First Powershell

Yes, PowerShell does appear to be as simple as I've heard about. What I do like and is contrary to my previous Hack and Slash post is the ability to just fire up the interpreter and "play." Tab completion allows for easy exploration of functionality. I'll have to read an actual book on it at some point in the future to plumb the depths of it as it seems like something everyone will need in their toolkit.

When new developers start or if we get a new machine here, there are some manual setup steps required. Trivial stuff but that can make for a good case for me to sample PowerShell.



# PowerShell 1.0 script
# 2009-09-10 bfellows
#
# This script is designed to facilitate the setup of new developer machines
# It creates two new machine level variables for CVS and SSIS and
# ensures the path to the CVS executable is in the system path
#

# Create variables and assign default values
$cvsPath = "C:\Program Files\CVSNT\"
$cvsRoot = "hostname=cvs.domain.com:/usr/cvs"
$ssisConfig = "Provider=SQLNCLI.1;Data Source=localhost;Integrated Security=SSPI;Initial Catalog=SYSDEVDB"
$pathDelimiter = ";"

# Snag the existing path into a dictionary
$path = Get-ChildItem Env:path

# Set the environment variables which you couldn't have guessed from the
# method call
[Environment]::SetEnvironmentVariable("SSIS_CONFIG", $ssisConfig, "Machine")
[Environment]::SetEnvironmentVariable("cvsroot", $cvsRoot, "Machine")

# If CVSNT isn't in the path (this assumes it has been installed)
if (! $path.Value.Contains($cvs))
{
# Append the cvs path, prefaced with a path delimiter
[Environment]::SetEnvironmentVariable($path.Name, $path.Value + $pathDelimiter + $cvsPath, "Machine")
}

No comments: