Powershell Cheatsheet

I just don’t use powershell enough to remember these things off the top of my head. Probably the simple act of writing them down will help me to remember, but in case not…

Allow running of scripts (must be admin) :
set-executionpolicy -executionpolicy RemoteSigned

Check file exists:
if(test-path file.txt) { #your code here }
if(!(test-path file.txt)) { #your code here }

Get the current directory of you script:
$mydir = (Split-Path -parent $MyInvocation.MyCommand.Definition)

Which you can combine with Join-Path to build a new path:
$mydir | Join-Path -ChildDir "subdir" | Join-Path -ChildDir somefile.txt

No comments yet

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 )

Connecting to %s

Follow

Get every new post delivered to your Inbox.