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