A few years ago, I explored using ChatGPT to write simple PowerShell scripts. The results were…less than impressive. But, it has had time to improve. The more data that a Large Language Model is exposed to, the more useful it becomes. Has ChatGPT gotten better at creating scripts? Let’s see!
I went back to ChatGPT and fed it the same prompt as before:
Write a PowerShell function which displays both a hexadecimal and binary representation of a given string.
The script that it generated for me not only worked the first time, but presented the output much more nicely than before:
So, progress!
But that is just one AI tool out there. Let’s see how Microsoft’s Copilot handles the same prompt.
Again, success, right off the bat. No errors.
These tools might very well have reached a point of being useful.
Update
I even asked Copilot if it could modify the script to generate tabular output (to match what the latest iteration of ChatGPT had given me). There was a bit of a glitch at the beginning of the table, but it worked for the most part.
PS C:\Users\gmmar> function Convert-StringToHexAndBinary {
>> param (
>> [string]$inputString
>> )
>>
>> # Create a table header
>> Write-Output "Character`tHexadecimal`tBinary"
>> Write-Output "-" * 40
>>
>> # Iterate over each character in the input string
>> foreach ($char in $inputString.ToCharArray()) {
>> # Convert character to hexadecimal
>> $hexRepresentation = '{0:X2}' -f [int][char]$char
>>
>> # Convert character to binary
>> $binaryRepresentation = '{0}' -f [Convert]::ToString([int][char]$char, 2).PadLeft(8, '0')
>>
>> # Display the results in tabular format
>> Write-Output "$char`t`t$hexRepresentation`t`t$binaryRepresentation"
>> }
>> }
PS C:\Users\gmmar>
PS C:\Users\gmmar> # Example usage
PS C:\Users\gmmar> Convert-StringToHexAndBinary -inputString "Hello, World!"
Character Hexadecimal Binary
-
*
40
H 48 01001000
e 65 01100101
l 6C 01101100
l 6C 01101100
o 6F 01101111
, 2C 00101100
20 00100000
W 57 01010111
o 6F 01101111
r 72 01110010
l 6C 01101100
d 64 01100100
! 21 00100001