2017-12-27 3 views
0

저는 powershell 스크립팅 (그리고 generalling 프로그래밍/스크립팅)을 처음 접했고 이것은 첫 번째 powershell 스크립트입니다. Linux Subsystem을 PC에 설치하는 스크립트를 작성하려고합니다. 여기에 내가 스크립트가 관리 privliges (다시 찾을 수 없습니다) 실행되고 있는지 확인하는 if 문을했다 코드Powershell 스크립트는 "실행중인 스크립트가이 시스템에서 비활성화되어"있기 때문에 자체 호출 할 수 없습니다.

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 "& 
{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 

입니다. 또한 Fedora 호스트의 VM 내에서 실행 중입니다. 나는 "스크립트를 실행하는 것이이 시스템에서 불가능하기 때문에"스스로를 호출 할 수 없다는 것을 매우 이상하게 생각한다. if 문을 꺼내서 모든 것이 잘 실행되고 WSL이 설치됩니다.

답변

0

"스크립트 실행 중 ... 사용 안 함 ..."은 PowerShell 실행 정책이 "제한됨"으로 설정되었음을 나타냅니다. Get-Help about_Execution_Policies을 참조하십시오.

스크립트를 실행하려면 PowerShell 세션을 관리자로 실행하고 해당 세션 내에서 Set-ExecutionPolicy 실행 정책을 실행해야합니다. (a) 필요에 맞는 적절한 보안을 제공하고 (b) 안전하고 편한 스크립트를 실행하십시오. Get-Help Set-ExecutionPolicy을 참조하십시오.

관련 문제