gpt-4-turbo-2024-04-09· OpenAI
WildChat-4.8M (AI2)
bat 파일에서 Powershell 명령을 실행하는 방법을 알려줘
- User
bat 파일에서 Powershell 명령을 실행하는 방법을 알려줘
- Assistant
Windows에서
.bat파일 내에서 PowerShell 스크립트나 명령을 실행하려면 몇 가지 방법을 사용할 수 있습니다. 여기 간단한 예시를 몇 가지 설명해 드리겠습니다:방법 1: 일반 명령 실행
가장 간단한 PowerShell 명령을 실행하는 방법은
powershell명령을.bat파일에 직접 넣는 것입니다:batch@echo off powershell -Command "Write-Output 'Hello from PowerShell'"-Command파라미터는 직접 PowerShell 코드를 실행하게 해 줍니다. Batch 파일에서 이 한 줄이 PowerShell 스크립트를 실행합니다.방법 2: 외부 PS1 파일 실행
만약 복잡한 PowerShell 스크립트를 실행하고 싶다면,
.ps1파일을 만들고 그 스크립트 파일을.bat파일에서 호출할 수 있습니다.script.ps1같은 이름으로 PowerShell 스크립트 파일을 작성합니다..bat파일에서 다음과 같이 호출합니다:
batch@echo off powershell -File "C:\path\to\script.ps1"