title: PowerShell script can't call itself because "running scripts is disabled on this system"
body: <p>I'm trying to write a script that installs the Linux Subsystem onto the PC. Here is the code:</p>
  
  <pre><code>function Get-ScriptDirectory { # Gets scripts full path
      Split-Path -parent $PSCommandPath
  }
  
  If (-NOT ([Security.Principal.WindowsPrincipal]
    [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
    [Security.Principal.WindowsBuiltInRole] "Administrator")) #checks if script is being run as admin
  {
      Set-Location -Path $PSScriptRoot
      PowerShell -NoProfile -ExecutionPolicy Unrestricted -Command "&amp;
      {
          Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy
          Unrestricted -File ""Get-ScriptDirectory""' -Verb RunAs}"; # Starts
              #Powershell with admin permissions and executes this script.
      Break
  }
  Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux #Installs WSL
  </code></pre>
  
  <p>I had to take the <code>if</code> statement that checks if the script is being run with system administrator privileges (can't seem to find it again). I'm also running this within a VM on a <a href="http://en.wikipedia.org/wiki/Fedora_%28operating_system%29" rel="nofollow noreferrer">Fedora</a> host. I think the fact that it can't call itself because "running scripts is disabled on this system" to be very strange. I took out the <code>if</code> statement and everything runs fine and it installs WSL.</p>