AI 생성 스크립트를 사용하여 자동화를 통해 반복 작업 제거

AI 생성 스크립트를 사용하여 자동화를 통해 반복 작업 제거

지루한 컴퓨터 작업에 갇힌 적이 있나요? 당신만 그런 것은 아닙니다! 좋은 소식은 인공 지능(AI)의 약간의 도움으로 PowerShell 스크립트를 사용하여 Windows 작업을 간소화하고 자동화하여 더 중요한 활동에 귀중한 시간을 할애할 수 있다는 것입니다.

PowerShell 개요: 자동화 동맹

PowerShell은 강력한 명령줄 셸과 Windows에 내장된 포괄적인 스크립팅 언어 역할을 하며, 놀라운 관리 및 자동화 솔루션을 제공합니다.Microsoft 에 따르면, 컴퓨터에서 작업을 관리하는 방식을 바꿀 수 있는 도구입니다.

PowerShell 인터페이스

PowerShell을 사용하면 명령과 지침이 담긴 독립형 파일인 스크립트를 만들어 기본 파일 관리부터 복잡한 시스템 작업까지 모든 것을 자동화할 수 있습니다.

스크립팅을 처음 접하는 사람들을 위해, 수많은 사전 작성된 PowerShell 스크립트를 온라인에서 이용할 수 있습니다.예를 들어, PowerShell Scripts Repository에는 드라이브 공간 모니터링, 설치된 프로그램 나열, 생성 날짜별 사진 정리 등 다양한 작업을 지원하도록 설계된 500개 이상의 무료 스크립트가 있습니다.

이러한 바로 사용 가능한 스크립트가 가치 있는 것은 사실이지만 PowerShell의 진정한 잠재력은 특정 요구 사항에 맞춰 맞춤형 스크립트를 만드는 능력에 있습니다.바로 여기에서 AI가 게임 체인저가 됩니다!

AI를 활용하여 사용자 정의 PowerShell 스크립트 생성

손상된 하드 드라이브에서 복구된 수천 개의 파일을 정리해야 한다고 상상해보세요. PowerShell 구문을 마스터하거나 이상적인 기존 스크립트를 찾는 데 몇 시간을 보내는 대신, ChatGPT를 사용하여 사용자 지정 스크립트를 만들었습니다.

내 특정 요구 사항(이미지, 오디오, 문서 등 다양한 유형의 파일 정렬)을 위해 AI에 대한 명확하고 간결한 프롬프트를 만들었습니다.

PowerShell용 AI 프롬프트

제가 AI 프롬프트에 포함시킨 내용은 다음과 같습니다.

  • 어떤 카테고리에도 맞지 않는 파일을 처리하는 방법에 대한 지침입니다.
  • 파일을 확장자별로 정리하는 정확한 작업입니다.
  • 각 그룹의 범주 및 파일 유형에 대한 분석입니다.

AI는 내 파일 정리 작업을 처리하는 효과적인 PowerShell 스크립트를 빠르게 생성했습니다.

# Define the source folder as the current directory where the script is executed$sourceFolder = $PSScriptRoot# Define category folders and their associated file extensions$categories = @{ "Images" = @(".jpg", ".jpeg", ".png", ".gif", ".bmp", ".tiff", ".webp", ".svg", ".ico", ".raw", ".cr2", ".nef", ".heic", ".psd", ".ai", ".eps") "Documents" = @(".pdf", ".docx", ".doc", ".txt", ".rtf", ".xlsx", ".xls", ".pptx", ".ppt", ".odt", ".ods", ".odp", ".md", ".csv", ".json", ".xml", ".html", ".htm", ".log", ".tex", ".epub", ".mobi") "Audio" = @(".mp3", ".wav", ".aac", ".flac", ".ogg", ".wma", ".m4a", ".mid", ".midi", ".aiff", ".alac", ".ape", ".opus", ".amr", ".au", ".voc") "Video" = @(".mp4", ".avi", ".mov", ".wmv", ".mkv", ".flv", ".webm", ".m4v", ".mpg", ".mpeg", ".3gp", ".3g2", ".ts", ".vob", ".ogv", ".divx", ".asf", ".rm", ".rmvb") "Archives" = @(".zip", ".rar", ".7z", ".tar", ".gz", ".bz2", ".xz", ".cab", ".iso", ".tgz", ".tbz2", ".lzh", ".dmg", ".pkg", ".deb", ".rpm") "Code" = @(".py", ".js", ".html", ".css", ".java", ".c", ".cpp", ".cs", ".php", ".rb", ".go", ".swift", ".sql", ".ps1", ".sh", ".bat", ".vbs", ".ts", ".jsx", ".r", ".pl", ".lua") "Executables" = @(".exe", ".msi", ".app", ".apk", ".dll", ".bin", ".com", ".jar", ".gadget", ".wsf", ".appx", ".appxbundle") "Other" = @()}# Create category folders if they don't existforeach ($category in $categories. Keys) { $categoryPath = Join-Path -Path $sourceFolder -ChildPath $category if (-not (Test-Path -Path $categoryPath)) { New-Item -Path $categoryPath -ItemType Directory | Out-Null Write-Host "Created folder: $category" }} # Get all files in the source folder (non-recursive)$files = Get-ChildItem -Path $sourceFolder -File | Where-Object { $_. Name -ne $MyInvocation. MyCommand. Name } # Counter for moved files$movedFiles = 0$totalFiles = $files. CountWrite-Host "Starting to organize $totalFiles files..." # Process each fileforeach ($file in $files) { $extension = $file. Extension. ToLower() $targetCategory = "Other" # Determine which category the file belongs to foreach ($category in $categories. Keys) { if ($category -eq "Other") { continue } if ($categories[$category] -contains $extension) { $targetCategory = $category break } } # Move the file to the appropriate category folder $targetPath = Join-Path -Path $sourceFolder -ChildPath $targetCategory $targetFile = Join-Path -Path $targetPath -ChildPath $file. Name # Check if target file already exists and handle accordingly if (Test-Path -Path $targetFile) { $baseName = [System. IO. Path]::GetFileNameWithoutExtension($file. Name) $newName = "$baseName`_$(Get-Random)$extension" $targetFile = Join-Path -Path $targetPath -ChildPath $newName } Move-Item -Path $file. FullName -Destination $targetFile $movedFiles++ # Show progress $percentComplete = [math]::Round(($movedFiles / $totalFiles) * 100, 2) Write-Progress -Activity "Organizing Files" -Status "$movedFiles of $totalFiles files processed ($percentComplete%)" -PercentComplete $percentComplete } Write-Host "File organization complete! Moved $movedFiles files into categories."

작업 스케줄러를 사용하여 PowerShell 스크립트 자동화

AI가 생성한 PowerShell 스크립트의 마법은 생성에서 끝나지 않습니다.자동으로 실행되도록 설정하여 인간의 개입이 필요 없게 만들 수도 있습니다!

긴 컴퓨터 세션 중에 종종 휴식을 간과하기 때문에, 짧은 휴식을 취하라는 알림을 주는 스크립트를 만들었습니다.다시 한번, AI를 사용하여 간단한 프롬프트로 이 알림 스크립트를 생성했습니다.

휴식 시간 알림을 위한 AI 프롬프트

그 결과 PowerShell 스크립트는 내 요구 사항에 완벽하게 맞춰졌습니다.

# Script to remind user to take regular screen breaks # Load required assemblies for notifications Add-Type -AssemblyName System. Windows. Forms# Function to show break reminder notification function Show-BreakReminder { $motivationalMessages = @( "Time for a 5-minute break! Rest your eyes and stretch.", "Screen break time! Look at something 20 feet away for 20 seconds.", "Break time! Stand up and move around for 5 minutes.", "Your eyes need a rest! Take 5 minutes away from the screen.", "Productivity hack: A 5-minute break now will boost your focus!" ) # Select a random message $randomMessage = $motivationalMessages | Get-Random # Create and configure the notification $notification = New-Object System. Windows. Forms. NotifyIcon $notification. Icon = [System. Drawing. SystemIcons]::Information $notification. BalloonTipTitle = "Wellness Reminder" $notification. BalloonTipText = $randomMessage $notification. Visible = $true # Show notification for 10 seconds $notification. ShowBalloonTip(10000) # Clean up after a delay Start-Sleep -Seconds 12 $notification. Dispose() } # Display an initial notification Show-BreakReminder Write-Host "Break reminder displayed. Set this script to run hourly using Task Scheduler."

이제 스크립트가 있으니 Windows 작업 스케줄러를 통해 매 시간 자동으로 실행되도록 설정했습니다.방법은 다음과 같습니다.

작업 스케줄러 기본 작업

첫째, AI에서 생성한 스크립트를.ps1 파일로 저장하고 시작 메뉴를 통해 작업 스케줄러 에 액세스했습니다.매일 트리거가 있는 새로운 기본 작업을 만들었습니다.

작업 스케줄러에서 트리거 편집

트리거 설정을 수정하여 매시간 작업을 실행했습니다.작업 스케줄러 라이브러리에서 작업을 찾은 후 마우스 오른쪽 버튼을 클릭하고 속성을 선택했습니다.트리거 탭에서 편집을 클릭하고 작업 반복 간격: 옵션을 체크하고 간격을 1시간 으로 설정 했습니다.또한 기간에서 무기한을 선택 하고 확인을 클릭하여 변경 사항을 저장했습니다.

작업 스케줄러의 트리거 속성

다음으로, 속성 창에서 작업 탭으로 이동하여 편집을 클릭하여 작업 설정을 조정했습니다.프로그램/스크립트 필드의 경우 powershell.exe스크립트의 직접 경로 대신 입력했습니다.인수 추가 필드에서 -ExecutionPolicy Bypass -WindowStyle Hidden -File "C:\Users\David\Desktop\eye-saver.ps1"실행 정책과 스크립트의 전체 경로를 모두 포함하는 를 사용했습니다.

Eye Saver PowerShell 스크립트 설정

이러한 설정을 저장한 후 확인을 두 번 클릭하여 속성 창을 마무리했습니다.결과는? 눈의 피로를 줄이는 동시에 생산성을 높여주는 원활하게 실행되는 알림!

PowerShell 스크립트를 만들고 자동화하는 데 AI를 사용하는 것의 장점은 일상에 놀라운 효율성을 도입한다는 것입니다.이러한 간단한 명령을 사용하면 더 나은 워크플로를 촉진할 뿐만 아니라 컴퓨터가 백그라운드에서 조용히 작업을 수행하도록 할 수 있습니다.

모든 이미지와 스크린샷의 출처는 David Morelo입니다.

자주 묻는 질문

1. PowerShell 스크립트를 만들려면 프로그래밍 지식이 필요합니까?

아니요, 광범위한 프로그래밍 지식이 필요하지 않습니다. ChatGPT와 같은 AI 도구를 사용하면 원하는 것을 간단히 설명하여 스크립트를 생성하여 모든 사람이 접근할 수 있도록 할 수 있습니다.

2. PowerShell 스크립트를 자동으로 실행하려면 어떻게 해야 하나요?

Windows 작업 스케줄러를 사용하여 PowerShell 스크립트를 예약할 수 있습니다.이를 통해 지정된 간격으로 실행하여 추가 작업 없이 작업을 자동화할 수 있습니다.

3. AI가 생성한 스크립트가 예상대로 작동하지 않으면 어떻게 되나요?

초기 스크립트에 조정이 필요한 경우가 많습니다.생성된 코드를 검토하고 경로가 정확한지 확인하고 매개변수를 조정하세요. PowerShell 설명서를 참조하여 문제 해결을 주저하지 마세요!

출처 및 이미지

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다