Powershell

File System

Search in files

# -r for recurse, -i include on *.js files. Then piped into the Select-String command
ls -r -i *.js | Select-String "text to search for"

Remove Directory

# -r for recurse, -fo for force, deletes dir and all subdirs
rm -r -fo DirectoryName

Environment Variables

User Level

Creates a variable that will exist permanently, requires powershell be restarted for var to become available

# Set user-level var
[Environment]::SetEnvironmentVariable("dev","C:\dev\work","User")

# Restart powershell to access new var
cd $env:dev

Process Level

Var only exists for as long as your powershell session lasts

# Create new environment var
$env:DEV = "c:\dev\work"

# Use new environment var
cd $env:DEV

Running commands

Use the & symbol to execute a command

$env:edit = "C:\Program Files\Sublime Text 2\sublime_text.exe"
&$env:edit foo.txt

Misc

Get Powershell Version

$Host.Version

d

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s