Using ChatGPT to write PowerShell scripts, SQL code, etc


x509

Well-known member
Member
VIP
Local time
8:51 PM
Posts
186
Location
Western USA
OS
Windows 11
I've started to play around, nothing too serious yet, with asking ChatGPT, the free version, to write PowerShell scripts. I'm not proud of that but this grey old head doesn't learn new languages the way he used to when he listened to ABBA and the BeeGees.

So I'm wondering what more experienced people think of htis idea. Am I just causing headaches for myself? Better AI models than ChatGPT for this purpose?

I kinda/sorta/not really know SQL, so I'm also thinking I could use ChatGPT to write scripts programs that use sqlite3 database. And if all that works, then maybe even lua scripts for Adobe Lightroom Classic.
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
    Manufacturer/Model
    home built
    CPU
    AMD 7900x
    Motherboard
    ASUS AMD x670E ROG Strix E-A
    Memory
    64 GB
    Graphics Card(s)
    Nvidia 3060 Ti (but wanting to upgrade)
    Sound Card
    built-in
    Monitor(s) Displays
    Dell 24"
    Cooling
    AIO for CPU, fans for case
    Keyboard
    Das Keyboard 4
    Mouse
    Corsair M65 (white)
    Browser
    Firefox
    Antivirus
    Bitdefender
    Other Info
    Also have Lenovo T14S laptop (me) and Lenovo Slim 71 (wife)
1. the script will be working.
2. the code quality is mediocre.

hence, we tried awhile but not any longer.
my computers are mainly running python, excel macro, , ,
 

My Computer

System One

  • OS
    Windows 7/11
    Computer type
    PC/Desktop
    Manufacturer/Model
    HP/Lenovo/Asus
    CPU
    Intel i7-11800H
    Motherboard
    Lenovo Legion 5i Pro Gen 6
    Memory
    32GB DDR4 3200MHz
    Graphics Card(s)
    NVIDIA GeForce RTX 3070
    Hard Drives
    1TB PCIe SSD
GitHub Copilot is better at writing code. It is purpose-built for this.
 

My Computers

System One System Two

  • OS
    Windows 11 Pro 24H2
    Computer type
    PC/Desktop
    Manufacturer/Model
    Intel NUC12WSHi7
    CPU
    12th Gen Intel Core i7-1260P, 2100 MHz
    Motherboard
    NUC12WSBi7
    Memory
    64 GB
    Graphics Card(s)
    Intel Iris Xe
    Sound Card
    built-in Realtek HD audio
    Monitor(s) Displays
    Dell U3219Q
    Screen Resolution
    3840x2160 @ 60Hz
    Hard Drives
    Samsung SSD 990 PRO 1TB
    Keyboard
    CODE 104-Key Mechanical with Cherry MX Clears
    Antivirus
    Microsoft Defender
  • Operating System
    Linux Mint 21.2 (Cinnamon)
    Computer type
    PC/Desktop
    Manufacturer/Model
    Intel NUC8i5BEH
    CPU
    Intel Core i5-8259U CPU @ 2.30GHz
    Memory
    32 GB
    Graphics card(s)
    Iris Plus 655
    Keyboard
    CODE 104-Key Mechanical with Cherry MX Clears
I use ChatGPT to code for me with some success. But only simple things.
 

My Computers

System One System Two

  • OS
    Windows 11 Pro 24H2 26100.2894
    Computer type
    Laptop
    Manufacturer/Model
    Acer Swift SF114-34
    CPU
    Pentium Silver N6000 1.10GHz
    Memory
    4GB
    Screen Resolution
    1920 x 1080
    Hard Drives
    SSD
    Cooling
    fanless
    Internet Speed
    150 Mbps
    Browser
    Brave
    Antivirus
    Webroot Secure Anywhere
    Other Info
    System 3

    ASUS T100TA Transformer
    Processor Intel Atom Z3740 @ 1.33GHz
    Installed RAM 2.00 GB (1.89 GB usable)
    System type 32-bit operating system, x64-based processor

    Edition Windows 10 Home
    Version 22H2 build 19045.3570
  • Operating System
    Windows 11 Pro 23H2 22631.2506
    Computer type
    Laptop
    Manufacturer/Model
    HP Mini 210-1090NR PC (bought in late 2009!)
    CPU
    Atom N450 1.66GHz
    Memory
    2GB
    Browser
    Brave
    Antivirus
    Webroot
I use AI a lot as a coding aid (mostly GitHub Copilot with C#). It relieves me of a lot of tedious research and trial and error to get the structure and syntax correct for Windows APIs.

In general, the smaller the task you give it each time, the greater the success. But a smaller command line tool can be written almost in one go if you give it good instructions. The best instructions are pseudo code. If you write out well thought out pseudo code, the AI can translate that into whatever language you choose.

I find that the results are better with a stricter language, such as C#, than PowerShell. You must also be sure to tell the AI the target context (.Net version, PowerShell version, etc.). For programs with a GUI, you have to break things up into well organized pieces in order to effectively use AI, but it can't see the GUI results, so it's a lot of back and forth.

You have to always keep in mind that it can't see over your shoulder, but it can see your existing code in Copilot. Copilot is also handy for things like code review. You can ask it to review your code and suggest improvements and it usually finds something.
 

My Computer

System One

  • OS
    Windows 10/11
    Computer type
    Laptop
    Manufacturer/Model
    Acer
I also use AI for refrence on daily basis for small code questions. Somehow i do like CoPilot, however copy pasting from there always seem to go wrong. Go wrong in that some sections i select, get deselected when copying.. So i use other AI websites, and not use CoPilot, maybe once a week, when other AI can't get things right.
For code reviews i use LLM Local AI, so that the codes not get stolen and used in training for AI models. So that means i only ask questions to internet AI on how to do something, rather then copy en past existing code and ask it to change it.
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
Here is a good example of why I use ChatGPT. I asked "how to enable hibernate".

To enable Hibernate in Windows 11 (or Windows 10), follow these steps:


1. Enable Hibernate in Power Options


  1. Press Win + R, type control, and press Enter to open the Control Panel.
  2. Go to Hardware and Sound > Power Options.
  3. Click Choose what the power buttons do from the left panel.
  4. Click Change settings that are currently unavailable.
  5. Under Shutdown settings, tick Hibernate.
  6. Click Save changes.

2. Check if Hibernate is Enabled in the System


  1. Open Command Prompt as Administrator.
  2. Run this command:
    powercfg /availablesleepstates<br>
    If Hibernate is not listed, continue to step 3.

3. Enable Hibernate via Command Line (If Needed)


  1. Open Command Prompt as Administrator.
  2. Type the following and press Enter:
    powercfg /hibernate on<br>

4. Verify Hibernate File Size (Optional)


The hibernation file (hiberfil.sys) can be adjusted for faster startup:


  • To reduce it to 50% of RAM size(enough for Fast Startup but not full hibernation):
    powercfg /h /type reduced<br>
  • To restore full hibernation:
    powercfg /h /type full<br>

5. Add Hibernate to Start Menu (If Missing)


If you don’t see Hibernate in the Start menu:


  1. Go to Control Panel > Power Options.
  2. Click Choose what the power buttons do.
  3. Tick Hibernate under Shutdown settings.

After this, Hibernate should work. Let me know if you run into issues.
 

My Computers

System One System Two

  • OS
    Windows 11 Pro 24H2 26100.2894
    Computer type
    Laptop
    Manufacturer/Model
    Acer Swift SF114-34
    CPU
    Pentium Silver N6000 1.10GHz
    Memory
    4GB
    Screen Resolution
    1920 x 1080
    Hard Drives
    SSD
    Cooling
    fanless
    Internet Speed
    150 Mbps
    Browser
    Brave
    Antivirus
    Webroot Secure Anywhere
    Other Info
    System 3

    ASUS T100TA Transformer
    Processor Intel Atom Z3740 @ 1.33GHz
    Installed RAM 2.00 GB (1.89 GB usable)
    System type 32-bit operating system, x64-based processor

    Edition Windows 10 Home
    Version 22H2 build 19045.3570
  • Operating System
    Windows 11 Pro 23H2 22631.2506
    Computer type
    Laptop
    Manufacturer/Model
    HP Mini 210-1090NR PC (bought in late 2009!)
    CPU
    Atom N450 1.66GHz
    Memory
    2GB
    Browser
    Brave
    Antivirus
    Webroot
GitHub Copilot with C#… relieves me of a lot of tedious research and trial and error to get the structure and syntax correct for Windows APIs.
Check out CsWin32 in NuGet.
 

My Computers

System One System Two

  • OS
    Windows 11 Pro 24H2
    Computer type
    PC/Desktop
    Manufacturer/Model
    Intel NUC12WSHi7
    CPU
    12th Gen Intel Core i7-1260P, 2100 MHz
    Motherboard
    NUC12WSBi7
    Memory
    64 GB
    Graphics Card(s)
    Intel Iris Xe
    Sound Card
    built-in Realtek HD audio
    Monitor(s) Displays
    Dell U3219Q
    Screen Resolution
    3840x2160 @ 60Hz
    Hard Drives
    Samsung SSD 990 PRO 1TB
    Keyboard
    CODE 104-Key Mechanical with Cherry MX Clears
    Antivirus
    Microsoft Defender
  • Operating System
    Linux Mint 21.2 (Cinnamon)
    Computer type
    PC/Desktop
    Manufacturer/Model
    Intel NUC8i5BEH
    CPU
    Intel Core i5-8259U CPU @ 2.30GHz
    Memory
    32 GB
    Graphics card(s)
    Iris Plus 655
    Keyboard
    CODE 104-Key Mechanical with Cherry MX Clears

Latest Support Threads

Back
Top Bottom