What’s the best way to determine the location of the current PowerShell script?

Whenever I need to reference a common module or script, I like to use paths relative to the current script file. That way, my script can always find other scripts in the library. So, what is the best, standard way of determining the directory of the current script? Currently, I’m doing: $MyDir = [System.IO.Path]::GetDirectoryName($myInvocation.MyCommand.Definition) I … Read more

How to run a PowerShell script

How do I run a PowerShell script? I have a script named myscript.ps1 I have all the necessary frameworks installed I set that execution policy thing I have followed the instructions on this MSDN help page and am trying to run it like so: powershell.exe ‘C:\my_path\yada_yada\run_import_script.ps1’ (with or without –noexit) which returns exactly nothing, except … Read more

PowerShell says “execution of scripts is disabled on this system.”

I am trying to run a cmd file that calls a PowerShell script from cmd.exe, but I am getting this error: Management_Install.ps1 cannot be loaded because the execution of scripts is disabled on this system. I ran this command: Set-ExecutionPolicy -ExecutionPolicy Unrestricted When I run Get-ExecutionPolicy from PowerShell, it returns Unrestricted. PS C:\Users\Administrator\> Get-ExecutionPolicy Unrestricted … Read more