Many developers have conflicting views when it comes to ChatGPT and its alleged capabilities. On one side, they worry that the platform could eventually put them out of work because of its ability to write code. On the other, they think ChatGPT is of no consequence because its scripting is weak. This led me to wonder: can ChatGPT write Powershell code? To answer that, I put ChatGPT’s scripting abilities to the test.
Test #1: A Basic Powershell Script
I started by asking ChatGPT to assist in creating a “Hello World” script in Powershell. As you can see from figure 1 the chatbot provided step by step instructions, from explaining how to open Powershell to the actual script. This experiment shows that ChatGPT can indeed write Powershell code.
Test#2: A Bigger Powershell Script
For this test I decided to give a more complicated example, one that isn’t Hello World, but still not too hard. I asked ChatGPT to create a script to count from 1 to 100, wait 250 milliseconds between each number, and display a progress bar. Here the code I wrote (figure 2) and the code ChatGPT wrote (figure 3). Even though the scripts are nearly identical, mine worked while ChatGPT’s didn’t. The first line of its script turned out to be the problem. When I asked ChatGPT to try again, it ended up writing a while loop (figure 4); though still had problems. I helped it fix them and it did, finally producing a successful script.
Brien Posey
Figure 1. ChatGPT gave me instructions for writing a Hello World script.
Brien Posey
Figure 2. Here is what it looks like when I run my script.
Brien Posey
Figure 3. Here is the code that ChatGPT created.
Brien Posey
Figure 4. ChatGPT has rewritten the code using a While loop.
Brien Posey
Figure 5. ChatGPT fixed the broken script it had written.
Since ChatGPT can indeed write Powershell scripts, still it is clear that it is not perfect yet. Its ability to create another loop on its own after the first one didn’t work and the provision of helpful instructions makes it apparent that it is really writing the scripts. However, it’s important to note that a human touch is still needed to make sure the PowerShell codes we receive are error free and correctly created.
ChatGPT is an AI-assisted coding platform with a mission to streamline the development process. Developed by the founders of Chatbridge, their team of engineers, scientists and creative minds are constantly looking for ways to improve the services they offer. They believe in the power of AI to empower developers, companies and individuals with easy, powerful and faster ways to accomplish software development. Brien Posey is a best-selling technology author, speaker and 21-time Microsoft MVP. In preparation for a mission to study polar mesospheric clouds from space, he has done extensive training as a commercial astronaut. He specializes in explaining complicated technical topics in simple terms and has written extensively on a variety of topics concerning the internet of things, Windows Server and virtualization.