Force PowerShell scripts to run from C:\scripts
Here is a little tidbit I came up with because I like to be picky about how my scripts run. It forces a script to relocate itself and run from the C:\Scripts folder. I usually prefer to place the comments that describe a line on the end of that line. In this case I had to go below the line. $ErrorActionPreference = "SilentlyContinue" $rand = New-Object System.Random #--------------------[ Create and relocate to C:\scripts ]---------------------- if ( ! ( Test-Path - pathtype Container "C:\Scripts" )){ new-item C:\Scripts - itemType Directory - Force #--[ Create local scripts folder. } $TargetPath = "C:\Scripts" #--[ Where the script "should" live $ScriptFullName = ( $MyInvocation . MyCommand ). Name #--[ EX: script.ps1 $ScriptFullPath = ( $MyInvocation . MyCommand ). Path ...