Artificial Intelligence, AI, is in the fast lane. Does it have a lasting impact? Read what our author has to say.
Wow, what a year it has been for OpenAI/ChatGPT and by year, I mean last week. Hopefully you’ve heard about ChatGPT, it’s been talked about, everywhere!
ChatGPT is an artificial intelligence (AI) chatbot developed by OpenAI. It is built on top of OpenAI's GPT-3.5 and GPT-4 foundational large language models (LLMs) and has been fine-tuned (an approach to transfer learning) using both supervised and reinforcement learning techniques, including human feedback.
Today, you can try ChatGPT for free at https://chat.openai.com/. You "program" ChatGPT by creating "prompts". A prompt is the text or statement that is given to the model to generate a response or output.
I asked ChatGPT to use PowerShell to list the even numbers between 1 and 10. ChatGPT responded with both code and explanation. Pretty interesting. Let’s do more.
The Chat in ChatGPT means just that. It is a sophisticated chat bot. I will now prompt it nine more characters one-liner, let’s see what happens.
ChatGPT remembers the conversation and has context! It takes my nine-character prompt, "expands" it applying it in context to our conversation. Sure enough, it produces a working example of runnable, correct PowerShell. Bonus points, it examples the line of PowerShell too!
This all happened in less then 30 seconds elapsed time, and I was using GPT-3.5. There is a GPT-4. It is more capable on many levels.
Microsoft GitHub Copilot
Announced in 2021, it is best described as your AI Pair Programmer. A smart developer, who can make mistakes, and mostly help you be more productive in more ways than I can describe in this article. GitHub Copilot uses OpenAI to suggest code and entire functions in real-time, right from your editor. It was trained on billions of lines of code, and it turns natural language prompts into coding suggestions across dozens of languages, including PowerShell.
When I do presentations on GPT and my PowerShell AI module (more on that later), I have this graphic:
You probably have seen, heard, or read about AI, and along the way you have met AI deniers, AI doom predictors and more.
AI is a tool, a skillset. Learning how to wield and apply this new technology can and will make you more productive. The challenge is, like any other new tool on the scene, you need to learn how to find and turn the knobs and dials.
When you first started with PowerShell, passing objects over the pipeline was a new, "revolutionary" idea. It is one of the reasons PowerShell makes you very productive. You had to invest time to figure out how it worked, how to fix errors in your code when something unexpected happened, and more.
ChatGPT/Copilot/PowerShellAI is no different. You need to invest time and learn how to integrate it into your workflow. I promise you; you won’t be disappointed.
I started using GitHub Copilot back in 2021, then ChatGPT on the web when it was released in November 2022. Learning the knobs and dials of this new technology is not like learning Math or Software Development. Prompt engineering is different, and I won’t go into detail here. I encourage you to ask ChatGPT about it or use more traditional ways to uncover more about it. Trust me, it is worth the time to invest in learning more.
OpenAI also offers REST APIs to access the GPT models. The models are what you prompt and then they respond. Being a PowerShell professional and knowing I can access these REST APIs I created the PowerShellAI. Why? One reason, to do deeper a diver on this amazing technology. The other reason, I wanted to have ChatGPT in my console, and my scripts.
Here is an example of using one of the functions in the module 'copilot'. You pass your prompt to it, same as you would to ChatGPT in the web. I want to know how to login to Azure and list all my resources group with the suffix '-rg'.
In your console you type that in and press enter. GPT responds with two lines of code. The copilot function takes the response and does syntax highlighting and more. Copilot then prompts you about what to do. 'Y' runs the code right there, 'E' will prompt GPT to "explain" the code it returned, 'C' will copy it to the clipboard.
In this example I asked it to explain the code. You can see the response.
I rarely use Stack Overflow or Google for coding anymore. The really cool thing is ChatGPT, PowerShellAI and GitHub Copilot all use the same models. The point is as you learn prompt engineering, each of these tools let you build your muscle in prompting. Each one presents the results differently, one in a web page, PowerShellAI enables you to run it directly in the console and GitHub Copilot inserts it in your script, in the VS Code IDE.
Productivity, Productivity, Productivity
I cannot stress enough how productive this is and I’m not the only one. Having a smart tech person at your fingertips is invaluable. AI will not replace you, someone who knows how to use these tools will. You shortcut Google and Stack Overflow searches, copy/paste is drastically reduce, and GPT is not limited to just providing PowerShell code.
Translate Between Programming Languages
You can ask GPT to translate code from another programming language. Here I go from python to PowerShell. Using copilot form the PowerShellAI:
After it responded, I pressed 'Y' to run the code in the console.
You can also go from PowerShell to Python.
Note: That prompt works in ChatGPT and GitHub Copilot.
Conclusion – Closing Thoughts
The integration of ChatGPT into the world of PowerShell script development is poised to have a profound and lasting impact. By empowering IT pros and developers to work more efficiently, collaborate more effectively, and create more secure and compliant scripts, ChatGPT is set to revolutionize the industry.
As the future of PowerShell development unfolds, it is clear that ChatGPT and other Generative AI tools will play a central role in shaping the way we build, maintain, and enhance our IT infrastructure.
The future of PowerShell script development is exciting, thanks to the rise of AI-enhanced developers and the capabilities offered by ChatGPT. Companies and IT professionals need to embrace these advancements to stay competitive and drive innovation in their organizations.
The integration of ChatGPT into the PowerShell process will accelerate and improve our development capabilities going forward.