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.

3 Comments

  • >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\/\/

  • You should put an example on how to use SET

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

    set x=abc

Comments have been disabled for this content.