r/PowerShell • u/_ouromoros • Mar 08 '23
PowerGPT: Run commands using natural language using GPT model
https://github.com/ouromoros/PowerGPT
Hi, I wrote a PowerShell module that offers a quick way to utilize power of GPT model to assist performing tasks in PowerShell. Basically it works like this:
$ PowerGPT "list all files in current folder with created date"
Will execute script:
-----
Get-ChildItem | Select-Object Name, CreationTime
-----
The functions and code are a little unpolished now but I already find it really handy to use. I would love to hear your opinions on it. Welcome to have a try :)
3
Mar 08 '23
Going to give this a try .ill be back
3
Mar 08 '23 edited Mar 08 '23
This is super helpful when it comes to trying to find out how to do something in powershell very fast
i know i just cant type anything but was testing ,
is this normal for you to see this error after something like this
PS:> powergpt "copy all files from Documents to desktop in a new folder then open youtube.com"
The description is a little vague, do you mean:
[0] Copy all files from Documents to desktop in a new folder.
[1] Create a new folder on desktop and copy all files from Documents to the new folder.
[2] Copy all files from Documents to a new folder on desktop and open youtube.com.
Choose one description that matches your task, or [n]o:When i type 2 i get
Invoke-RestMethod: { "error": { "message": "You didn't provide an API key. You need to provide your API key in an
Authorization header using Bearer auth (i.e. Authorization: Bearer YOUR_KEY), or as the password field (with blank
username) if you're accessing the API from your browser and are prompted for a username and password. You can obtain
an API key from https://platform.openai.com/account/api-keys.", "type": "invalid_request_error",
"param": null, "code": null } }Either way this is super cool!
6
u/_ouromoros Mar 09 '23
Just fixed it, a huge bug caught on sight, shame on me. You can update to `1.0.2` and hopefully it will work. Thanks for trying!
0
13
u/Billi0n_Air Mar 08 '23
Writing shell scripts can be difficult, sure...but boring?
C'mon Jack (in my joe biden voice)
4
u/YT-Deliveries Mar 09 '23
There's also a plugin for VS Code called "Rubberduck" that I've really liked: https://marketplace.visualstudio.com/items?itemName=Rubberduck.rubberduck-vscode&ref=producthunt
1
u/gate122 Mar 09 '23
I just downloaded VS Code 2 days ago. Still a learning curve to set up like Powershell ISE, which I am use to. Do you know any VS Code extension for Powershell that can imitate the cmdlet menu list in Powershell ISE?
1
u/YT-Deliveries Mar 09 '23
Sorry, I donβt. I really never used that feature. Iβm old so I tend to use IDEs as if they were just better looking versions of EMACS
1
u/gate122 Mar 09 '23
Thanks. I found a workaround. I install the latest PSReadline and turn on List View in PowerShell. That works just like ISE cmdlet list menu.
1
1
1
u/MrRad5000 Mar 19 '23
Hi this was working until today Im getting Invoke-restmethod : 502 Bad gateway nginx
2
u/_ouromoros Mar 19 '23
I just checked that it is working fine on my pc. Is it still happening consistently for you? Since the error is a server error, it might be network issue or something wrong with the openai's API...
1
u/MrRad5000 Mar 19 '23
Thanks for the reply and narrowing it down to my end. Ill try generating a new key tomorrow.
Ive been using powerGPT for about a week and while it has limitations its extremely helpful to get you started in the right direction. especially in learning powershell when a lot of search results send you to basic microsoft cmdlet pages.
3
u/Bassie_c Mar 08 '23
I think if AI keeps improving like this, r/itsaunixsystem can retire in a couple years π
User: Enhance image!
Mainframe:
*Generates an image with more pixels π*
1
1
u/old-dirty-olorin Mar 09 '23 edited Mar 09 '23
Anyone tested this with diskpart or DISM or robocopy modules? The module should run fine in a winPE environment?I will make a win10 VM tomorrow to test this.
1
1
31
u/lanerdofchristian Mar 08 '23
Props for not just running arbitrary code from a tool that only understands what code should look like.
Personally, I'm afraid this will still cause problems for less mindful users who put too much stock in what AI can currently do.