Powershell version of cmd set

If you are like me and are just so used to typing set to list and set environment variables then you might find this script useful.

if (test-path alias:set) { remove-item alias:set > $null }
function set
{
	[string]$var = $args
	if ($var -eq "")
	{
		get-childitem env: | sort-object name
	}
	else
	{
		if ($var -match "^(\S*?)\s*=\s*(.*)$")
		{
			set-item -force -path "env:$($matches[1])" -value $matches[2];		
		}
		else
		{
			write-error "ERROR Usage: VAR=VALUE"
		}
	}	
}

Just add this script to your Powershell profile and you will be all set :)

PS: If anyone is interested I updated the Powershell Language definitions for CodeHTMLer, it now highlights more of the built-in stuff such as cmdlets and variables.

Published Thursday, February 8, 2007 3:24 PM by puzzlehacker

Comments

# re: Powershell version of cmd set

>PS: If anyone is interested I updated the Powershell Language definitions for CodeHTMLer

Great !

Lol, Just used it to format an example on my blog, did not see it, as the was no cmdlet in it most embedded IronPython.;-)

but it was one of the things on my WishList, sometimes corrected it myself

Greetings /\/\o\/\/

Saturday, February 10, 2007 4:41 PM by /\/\o\/\/

# re: Powershell version of cmd set

You should put an example on how to use SET

Thursday, July 12, 2007 11:29 AM by Andrew

# re: Powershell version of cmd set

Andrew - You use it just like you would use the basic cmd set.

set x=abc

Friday, July 13, 2007 12:48 AM by puzzlehacker