[PowerShell] 윈도우에서 파일 랜덤 실행

## 파일 리스트 생성 스크립트

$formats = @("*.mp4","*.mkv") # 실행할 파일 확장자
$dir = Split-Path $MyInvocation.MyCommand.Path
gci "$dir\*" -include $formats -recurse | Set-Content .\list.txt # 현재 폴더(하위 폴더 포함) 해서 list.txt 파일로 생성
## 파일 실행 스크립트

$file = Get-Content .\list.txt | Get-Random -Count 1

# 특정 프로그램으로 실행
Start-Process -FilePath "C:\Program Files\Honeyview\Honeyview.exe" -ArgumentList """$file"""

# 기본 프로그램으로 실행
Invoke-Item -Path """$file"""

파일 실행 스크립트에서 기본 혹은 특정 프로그램으로 실행 둘중 하나만 사용해야 함.

Leave a Comment