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  Klir Launches Game-Changing ChatGPT Integration with Microsoft Azure's OpenAI Service for its Comprehensive Water Management Platform

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

Obama’s Techno-Optimism Shifts as Democrats Navigate Changing Tech Landscape

Explore the evolution of tech policy from Obama's optimism to Harris's vision at the Democratic National Convention. What's next for Democrats in tech?

Tech Evolution: From Obama’s Optimism to Harris’s Vision

Explore the evolution of tech policy from Obama's optimism to Harris's vision at the Democratic National Convention. What's next for Democrats in tech?

Tonix Pharmaceuticals TNXP Shares Fall 14.61% After Q2 Earnings Report

Tonix Pharmaceuticals TNXP shares decline 14.61% post-Q2 earnings report. Evaluate investment strategy based on company updates and market dynamics.

The Future of Good Jobs: Why College Degrees are Essential through 2031

Discover the future of good jobs through 2031 and why college degrees are essential. Learn more about job projections and AI's influence.