Can ChatGPT Generate PowerShell Code?

Date:

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.

See also  Arizona Law Taps AI to Fight Deepfakes in Elections

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.

Frequently Asked Questions (FAQs) Related to the Above News

Please note that the FAQs provided on this page are based on the news article published. While we strive to provide accurate and up-to-date information, it is always recommended to consult relevant authorities or professionals before making any decisions or taking action based on the FAQs or the news article.

Share post:

Subscribe

Popular

More like this
Related

Samsung Unpacked Event Teases Exciting AI Features for Galaxy Z Fold 6 and More

Discover the latest AI features for Galaxy Z Fold 6 and more at Samsung's Unpacked event on July 10. Stay tuned for exciting updates!

Revolutionizing Ophthalmology: Quantum Computing’s Impact on Eye Health

Explore how quantum computing is changing ophthalmology with faster information processing and better treatment options.

Are You Missing Out on Nvidia? You May Already Be a Millionaire!

Don't miss out on Nvidia's AI stock potential - could turn $25,000 into $1 million! Dive into tech investments for huge returns!

Revolutionizing Business Growth Through AI & Machine Learning

Revolutionize your business growth with AI & Machine Learning. Learn six ways to use ML in your startup and drive success.