ChatGPT/VM Script
[ChatGPT] Hyper-V. Powershell 관리자 권한으로 실행하는 Script 제작
Pepuri
2023. 3. 1. 11:25
반응형
이전글
2023.02.25 - [ChatGPT] - ChatGPT. Copy-VHDX, New-VM Script 병합
ChatGPT. Copy-VHDX, New-VM Script 병합
이전글 2023.02.12 - [ChatGPT] - ChatGPT. Out-GridView 을 .Net 기반의 System.Windows.Forms 로 변경 ChatGPT. Out-GridView 을 .Net 기반의 System.Windows.Forms 로 변경 아래의 자료에서 .Net Framework class인 System.Drawing과 Sysmte.Win
blog.limcm.kr
이전에 VM을 생성하는 과정 중에 일부 명령어는 관리자 권한 실행이 필요합니다.
이 작업이 생각보다 매우 번거로울 수가 있습니다.
이 부분에 대해서 GPT에게 문의하였습니다.
아래의 부분은 제작된 스크립트의 앞에 삽입합니다.
# Check if script is running as Administrator
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
# Restart script as Administrator
Start-Process powershell.exe "-File `"$PSCommandPath`"" -Verb RunAs
exit
}
수정한 뒤 스크립트를 우클릭 - Run with Powershell 로 실행합니다.
스크립트가 관리자 권한으로 실행되어 있지 않으면,
아래와 같이 관리자 권한으로 다시 실행을 시도합니다. Yes 를 클릭하면,
아래와 같이 Administrator 권한으로 실행된 것을 확인할 수 있습니다.
반응형