Menulis skrip shell bisa jadi sulit dan membosankan. Modul ini akan membantu Anda melakukan tugas umum/pemrosesan batch di terminal Windows dalam hitungan detik meskipun Anda tidak tahu apa pun tentang PowerShell.
Cukup ketik dan jalankan PowerGPT
seperti ini dan model GPT akan melakukan sisanya untuk Anda:
$ PowerGPT " list all files in current folder with created date "
Will execute script:
-----
Get-ChildItem | Select-Object Name , CreationTime
-----
Bahkan bagi para ahli PowerShell, mengetik beberapa kata dan membiarkan model AI melakukan pekerjaan kotor tentu terdengar seperti cara yang lebih baik;)
Skrip ini diimplementasikan murni di PowerSell dan dikemas sebagai modul PowerShell.
-Chat
yang menggunakan model gpt-3.5-turbo. Kelebihan: lebih murah dan lebih cepat. Kekurangan: tidak dapat menghasilkan saran seperti model text-davinnci-3
.Invoke-RestMethod
sehingga sekarang sebagian besar bahasa dapat berfungsi. $ PowerGPT -Chat "列出所有文件"
我们使用`Get-ChildItem`来列出所有文件。
```
Get-ChildItem -Path "C:" -Recurse -File
```
这将列出C盘下所有文件,包括子文件夹中的文件。如果要列出当前文件夹下的所有文件,可以将`-Path`参数设置为`.`。
Will execute script:
-----
Get-ChildItem -Path "C:" -Recurse -File
-----
Install-Module PowerGPT
Anda memerlukan kunci API OpenAI untuk menggunakan modul ini . Perintah ini akan meminta masukan kunci API pada penggunaan pertama. Untuk menyetel ulang kunci API, gunakan opsi -ResetConfig
.
Penggunaan Dasar:
$ PowerGPT " list all files in current folder with created date "
Will execute script:
-----
Get-ChildItem | Select-Object Name , CreationTime
-----
continue ?([ y ]es , [ n ]o):
$ PowerGPT " extract compressed.tar.gz "
Will execute script:
-----
# Extract compressed.tar.gz in Windows using PowerShell
# First, check if the tar command is available
if ( ! ( Get-Command tar - ErrorAction SilentlyContinue)) {
# If not, install the tar command
Invoke-WebRequest - Uri " http://gnuwin32.sourceforge.net/downlinks/tar.exe.zip " - OutFile " tar.exe.zip "
Expand-Archive - Path " tar.exe.zip " - DestinationPath " $ env: ProgramFiles GnuWin32 "
# Add the tar command to the PATH
$ env: Path += " ; $ env: ProgramFiles GnuWin32 "
}
# Extract the compressed.tar.gz file
tar - xvzf compressed.tar.gz
-----
continue ?([ y ]es , [ n ]o):
$ PowerGPT " print the first line of all the files that begin with poet_ in current folder "
Will execute script:
-----
Get-ChildItem - Path . - Filter " poet_* " | ForEach-Object { Get-Content $_ .FullName | Select-Object - First 1 }
-----
continue ?([ y ]es , [ n ]o):
Untuk tugas yang kompleks, alat ini akan berperilaku cerdas dan memberikan pilihan bagi pengguna:
$ PowerGPT " print first lines and last lines for each file in current folder "
The description is too vague , do you mean:
[ 0 ] For each file in current directory , print the first line and then print the last line of the file.
[ 1 ] For each file in current directory , print the first line of the file. After that , for each file , print the last line of the file.
Choose one description that matches your task: : 1
Will execute script:
-----
Get-ChildItem | ForEach-Object {
$file = $_ .FullName
Write-Host " First line of $file : "
Get-Content $file - TotalCount 1
}
Get-ChildItem | ForEach-Object {
$file = $_ .FullName
Write-Host " Last line of $file : "
Get-Content $file - Tail 1
}
-----
continue ?([ y ]es , [ n ]o)
Dimungkinkan juga untuk menulis skrip menggunakan perpustakaan umum dalam bahasa lain:
$ PowerGPT " retrieve AzureDevops artifact for a build " - ShellVariant C #
The description is a little vague , do you mean:
[ 0 ] Use AzureDevops REST API to retrieve the artifact for a build.
[ 1 ] Use AzureDevops SDK to retrieve the artifact for a build.
Choose one description that matches your task , or [ n ]o: 0
using System;
using System.Net.Http;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
var organization = " your_organization " ;
var project = " your_project " ;
var buildId = " your_build_id " ;
var token = " your_token " ;
var client = new HttpClient();
client.DefaultRequestHeaders.Add( " Authorization " , $ " Bearer {token} " );
var url = $ " https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}/artifacts?api-version=5.1 " ;
var response = await client.GetAsync(url);
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);
}
}