YTread Logo
YTread Logo

Using Copilot & ChatGPT to write PowerShell

Aug 29, 2023
Yeah, it's not that favorite word of mine either, so what is that? The one that was in my brain when I started talking power, that one, oh that one, okay, so Praxis, move on and today it's just the three of us. Mark uh Todd and I and it's Todd's show today Emily is on vacation this week and Derek is in Seattle on the next slide from the 365 educon conference uh so today is Todd's show so he'll cover

using

the co-pilot and the chat. GPT will

write

Powershell. Our agenda for today is that we are going to cover what AI is.
using copilot chatgpt to write powershell
It might not be something you fully understand yet, so that'll be a good place to start and then we'll check it off. and kind of a level set for what the focus of our particular discussion is today because obviously what AI is is a huge topic, and then how it should be used and what are the tools that Todd has found that work pretty well for

using

these AIs? . tools to help you

write

Powershell so with that ahead Todd, I think four are yours and Julie and I will just be silent ice cream and I like ice cream oh I love ice cream no no you're not getting a chocolate shake today , there is no chocolate. right, that was the last one, that's right, so what is an AI?
using copilot chatgpt to write powershell

More Interesting Facts About,

using copilot chatgpt to write powershell...

I wanted to talk about this, start with this and obviously if you have something to say, jump into the chat room, my chat window is covered. right now so someone shout something we will help you have questions here we go I love you guys AI will never be able to replace these guys so what is AI? So AI has gotten huge and it's become one of those terms that almost makes no sense because it's so many things, so I wanted to spend a little time talking about some of them so there's some context for what you're talking about.
using copilot chatgpt to write powershell
I'll talk more later, so AI is a huge field. Some examples of AI that are applicable to what I do. What I'm going to talk about today are things like NLP, which is natural language processing. We've seen that for a while any of us who have Amazon's She Who Shall Not Be Named, there's natural language processing there or She Who Shall Not Be Named. Named after Apple, but that's the idea that computers can now listen to natural language, we don't have to have specific syntax and keywords and we can all speak with our normal voices, they can understand what we want to say and they can respond .
using copilot chatgpt to write powershell
In that same kind of language, another example of AI is machine learning, which is why it became very popular a few years ago. This is the idea that you can teach a computer how to do something and then the computer can learn to do it itself, so if any of you have seen Silicon Valley on HBO. There was that season where they had that hot dog app, not a hot dog, and they went through machine learning. They showed him a bunch of pictures of Hot Dogs showing where the hot dog was. there was the dog and then they showed him a bunch of other pictures and made him figure out for himself where the hot dogs were and then he reviewed and gave him some comments, some human comments and then basically, you know, every time someone had a photo .
You could see if there was a hot dog in it, which is an example of machine learning and the advantage of that is that once the machine is trained properly, it can learn a lot of things very, very quickly and that's what GPT chats about. and those things have, so we'll talk about that in a little bit of computer vision. I mentioned that is an example of AI which is not what we are doing, but this is what you know, the idea is like my phone. Now it has a feature where I take a photo and then I can crop out the things that I don't want anymore, so if I have a vacation photo, you know, the sunset and the beach, I can go into this photo and have it AI takes my kids out of the picture so I can feel really relaxed on vacation, so that's another example of AI that's been around for a while, so it's just this idea that AI can be a lot of things, So when we talk about it, try to be specific about what we're talking about.
One thing I want to mention is that machine learning with AI learns like humans do all the computing behind machine learning and AI is based on what scientists and doctors. It knows about the human mind, so it's designed to learn like we do, for better or worse, so it can implement biases, it can be deceived, all these kinds of things. I'm going to say this a lot in this talk today, but it's better if you don't think of AI as a computer or as software, it's better if you think of AI as a form of intelligence because it really is and I'll give you some examples. about that later and then I'll talk about that. machine learning and all that, when I talk about gbt chat, this is something that got everyone excited about the AI ​​that essentially read the internet in September 2021 and then because of the way the model was trained, it understood everything and when you're interacting with Chad GPT, that's exactly what you're doing.
You're talking to someone who knew everything on the Internet and understood it two years ago, so some terms I'm going to use now as we talk. about this, the first one is a neural network, so anyone who has heard anything about AI has heard of the neural network or the neural network. I have a slide on this and a couple of slides to explain how it works, but essentially this is how our brains work um the word network literally means a work like a piece of art that looks like a network and so if you think about synapses and neurons, they look like networks, that's how our brain works, that's how AI works, it uses these neural networks, so when I hear AI scientists talk about that's what those things are that are inside those networks. neural, well we have things that are like neurons, those are the little bits of data, we also have parameters, so when you hear someone talk about an AI Model and they say it has 170 million parameters or 47 trillion parameters.
A parameter is the connection between neurons and that connection has weight and context and that's how the AI ​​decides where to work its way through the neural network to find its answer. on the other side those parameters and what you know by going up to those parameters how do you decide which neuron to go to next um and the next thing we're going to talk about is sometimes when that happens your AI hallucinates and the hallucination in the AI ​​is when AI just does stupid things, so this is something you didn't get out of your Corpus, something you didn't read on a blog, this is something you just guessed, and that's why there are a number of funny examples of people putting something in Ai and it coming out. something that just didn't make much sense.
When I first started trying to use it to write Powershell, I would just create commands and say, "You know, here's a command that does your thing." I'm like that command doesn't exist um, so that's something you have to keep track of again, this is not a computer, it's not going to know that two plus two won't always equal four, you might have these hallucinations, like this that one way to handle hallucinations is by setting the temperature, so when you interact with an AI with an API or with prompts you can set the temperature, the higher temperature will be more random, more creative, the lower temperature will be more concise and more real, so Let's say you're using AI to write a program like we're going to do today, you'll want the temperature to be low, but if you want the AI ​​to do something like write you a poem, I had to write some music.
For me, this morning you want the temperature to be high, you want it to be creative, you wanted to just make up nonsense, so when you hear about temperatures, that's what alignment is, it's something that won't really come into our discussion much today, but how you listen More about AI, you will absolutely hear about alignment and that is the idea of ​​whether the mission and the objectives of the AI ​​that you are interacting with have the same objective as you, so the example is like my wife and I are We communicate all the time. but sometimes we don't communicate well I don't say the right thing she doesn't listen to the right thing things are happening and there is a lack of communication but generally we are aligned we are all moving in the same direction so she never misunderstands something and then burns down the house or it May it be because we're aligned, but that's something we don't know about AI because we're still trying to figure it out and the other thing is that it can't really be baked.
This is because not all goals and morals and everything are the same, so if you align an AI model, what do you align it with? When you hear people talk about how bad AI and alignment are, that's what you'll hear and ultimately the last one. The term is a big language model or a movie and that's that big neural network that you're going to interact with. These you know, GTP, GPT, AIS type, they will be full of that, talking about a chat. GPT, what the heck is a GPT anyway? That's one of those things that once everyone talked about it, you know, I had to know what it was, so G and GPT stand for generative and that means it's AI that invents new things.
If you think about AI, like the GPS in your car, it's a kind of AI, you know, artificial intelligence figures out the best route, but it doesn't create anything, it takes a map that you already have and the roads that you already have, it just tells you. says which one. way to go, it's not generating new things when you work with GPT chat, it's generating new things that you're saying you know, write a script that says that, blah, that script didn't exist before. It is generating new things, that is generative AI. P stands for pre-trained and that means that the model you're interacting with was given instructions on how to learn before it did its machine learning, so you know sometimes they treat the alignment problem that way, but these are This idea that you were given a framework for how to learn before you were given the things to learn and the T stands for Transformer and that was something that was a very important part of why we heard about AI.
This was developed by a Google Researcher I think in 2017. This was a new way of reading data to learn data and generate data again, another Silicon Valley reference if you notice there is a point where they talk about their compression algorithm and they talk about doing the interior. Our compression algorithm is kind of like the Transformer and this is the idea that when you're using machine learning and training a model on some text before the Transformer, it reads it from start to finish linearly and works things out. The Transformer says the words mean different things depending on what other words are in the sentence before and after them, so it makes these connections between the words and you get better context and better understanding, and it does that when you read them and It does so when it generates new words. text, so that's what a Transformer is, something very, very interesting, so I promised the slide on the neural network.
I think we all know that we're all nerds here. I think our first exposure to a neural network was 30 years ago with our data guy he was always talking about my neural network this my neural network that um and that's what we have this is how our brains work on a very small scale and how they work these big language models, so on the left you have I got your input, you know, write me a script that does blah and then the AI ​​starts walking through these neurons and says, I have this piece, which makes sense for it to happen to Then you go through all those parameters and those weights and those synapses, you say, "I think this is the next piece and then you go to the next piece and you say, 'Okay,' here are all the things that came before.
This is probably the next piece that happens and works its way through this neural network until it appears on the other end. and that's how we get our output. Now there's a couple of things to keep in mind here, if you look at this neural network in any given input, you can get any output, so again, this is it, you don't want to treat it like a computer. not two plus two equals four, it is not deterministic and deterministic means that the output can always be determined by the inputs, so two plus two equals four, that is deterministic.
AIS and people are probabilistic, meaning that as you make your way through the neural network, this next network hop What will happen next is probably correct, but not always, so you'll notice that if you're using the GPT chat every time you type a message and it gives you a reply there is a regeneration button and basically what that says is Shake everything up and run it through the neural network again and see what comes out on the other end because it is not deterministic and then you can see how it moves around there um yeah, that's not that favorite word of mine either, so what is that? one that was in my brain when I started talking that that one yes is not that important you can ask this you can ask the B CPT chat the same question twice and get two different answers absolutely and that actually comes up um I have I have a million stories, but I use these things for all kinds of things besides coding and one of them was last month.
We were back in my wife's hometown. It is the festival of her city of her. It's a small city. We are all sitting on the terrace and one of my. My nephewis drinking PBR and eating s'mores and someone said something about it and then my father-in-law said, "Well, this sounds like a country song, so I pick up my phone and tell GPT to write me a song in the style of Willie Nelson about the Water Carnival includes PBR and s'mores and he wrote a country song about that so I read it, it was great and then I hit the regenerate button and wrote a second song about the Water Carnival and PBR and sports because it wasn't deterministic, I just made it up every time it was a big hit at that party, by the way, yeah, so how are we going to use all of this to write better code?
What are we going to talk about today? Well, now that we're all AI experts, we have this tool here, uh, AI, how can we use it? It's like a genie in the bottle, that's how I think about it. I really just go to Ai and just ask him crazy wishes and you know, sometimes it works. , but for Powershell specifically and code in general. I only do Powershell, but this is the same for Python, whatever it is, it will make you faster, you will make fewer mistakes, your code will end up having more functionality and will have better documentation, you know , to borrow a line from a '90s infomercial eat all you want and still lose weight, that's what we're going through here, and while you can use it to write better code, better Powershell and all that, you can write better anything that you can write better country songs about, you know.
PBR and s'mores, so that's going to be our goal: to do that with the. I had an interesting discussion with some of the PMP guys the other day about this and Chris Kent, who writes some Powershell but also writes some JavaScript. and a few other things specifically mentioned that he found co-pilot and Chad GPT to be really good at writing Powershell, so that may be part of the reason you're having such good experiences with him, he tends to be really good at that stuff. The more I use it, I find it absolutely terrible to type well and that's interesting because I only write Powershell but for the GitHub

copilot

, which is obviously a specific programming tool, Powershell is not one of the languages ​​it natively supports. it's like Python and c-sharp and all that fancy stuff, but Powershell is like, well, you know, if you have a good day, you can do Powershell, so given the exam, you know, how lucky I am there, I can only imagine it.
Those high level languages, um, again, don't think of it as a computer or software, think of it as a form of intelligence, that's good, it's going to give you the best results, so if you think about it that way. What role is this intelligence going to play with the specific thing you are going to do? Do you want me to create something you know is new to you? Do you want me to help you while you write something on your own? to give you something that you've already written and know, pick out problems or things like that that will help you start figuring out how to use the tool now that I've been using it for a few months, I think.
Less about that, but as you're trying to figure out how to implement AI, that's a good way, so one of the things we talked about when we were preparing for this is that it's a very different headspace to be in for trigger. code to think about that process and send it through your fingers to the keyboard than to look at code that someone else has written and work on it and, depending on the type of code, depending on the mood you're in, how much coffee you've had That can be difficult to change, so if you are trying to use this, keep that in mind and then you will know how to segment how you are going to use it.
Will you have me look at your code and give you examples? Are you going to ask you to write the code and read it yourself? That's something I like. I haven't struggled with it much, but I know that Julie Gets In the Zone is a lot deeper than me, her attention span is better than mine, so for her to get out of that, that's hard, one of the things that I love it and what I use AI for all the time is defeating the tyranny of the blank page and this is the idea that it's so hard to figure out how to start something once it starts and you have some collaborative things like that, but just that blank page so I often go to

chatgpt

and just do that.
I need this and even if it's terrible and I don't use one bit, it just put those juices flowing um and for GitHub

copilot

that last example you know comment Go through that's a great way to use GitHub copilot is put comments and just see how you write the code or the comments for that mark behind you and then Again we're going to talk about a couple of tools, but we just know which tool does what you're trying to do best and I'm going through the comments correctly, so the first one it's GitHub copilot, so yeah I still haven't realized that Microsoft is naming all of their AI stuff after something copilot, uh, M365 copilot, Windows copilot, whatever, GitHub copilot, while a We at Praxis love to criticize Microsoft for misnaming things and they give us more than enough to do that.
I actually think this is a pretty good name. This is a great way to look at this as it's just that person sitting next to you looking over your shoulder and suggesting things, but again, it's the cult pilot, so if he suggests something dumb, just don't do it, it's Like a GPS in that sense, I would never put a route in my GPS and just follow it if it sends me off a cliff. I would never go to the copilot and tell him to write me some code to do this and then just log it and go like that, you know, it's kind of like pair programming, uh trend that we saw in the late 90s and early 2000s , you only have a couple of people working on code for GitHub co. -pilot uses the Corpus it was trained on, so again there are these languages ​​that you know very well and then some other languages ​​that you know less, use the other open tabs that you have in that instance of vs code and also use the code that you are from top to bottom, so what's not restricted is if you're in the middle of a document, um, you can't know that you can read the above, but I can also read the material below, so if you come back in the middle of a document you start adding some things, you know the variables that are initialized later in the program, things like that, um, so it's very useful for that and really the way that I do that, I'll show you in a couple of slides.
I start documenting things and see what it does. I've seen this cost ten dollars a month and twenty dollars a month. I wasn't sure which one, so I put in 20. So this is very quick. These questions and practices aren't good for demonstrations, so we didn't do any of them, but this is just to give you an idea of ​​how to get started. I opened this up and you can see the arrow is pointing down. to the GitHub copilot icon down there when it's the smiley face, that means it's done when he's thinking in the background, he does this little spinning thing, so if you see it spinning, give it a minute.
I think it looks like a little squirrel. It doesn't do it on this side or a frog, a frog or a squirrel, that's not how you squint, yeah, a frog with braces, real straight teeth, yeah, so I walked in here and it had a code on the back . It just happened that I didn't mean to, but I went into the comment and said connect M365 with PNP Powershell and that gray text there just typed the line hooray, so I hit Tab and we were off, um now if I had been adding something. right, real code, I probably wouldn't have logged into the management part of that tenant, but that's what it gave me, so I said, get me all the listings on this site and it came back with get PNP listing, yeah, do that, but as I was thinking, I don't really need all the lists so I said show me the lists that aren't hidden or the system because I really want to do something so I did it and it gave them back to me and that's the Powershell that does that um and then I said : ok, assign them all to a variable for me and note that you understand the context, note that I didn't have to say assign all lists that are not. end of the hidden system for blah blah blah I said them and I knew who they were so I created that variable and then for the grand finale I said if there isn't a list called Todd's stuff, create it so it groups all of that together. and type pull out the code, that whole exchange took me 45 seconds, something like that, um, so now it's like it's a GPS, you want to check it, it absolutely does things wrong, it makes things up, but that's how you use one of the ways you can use this.
They also have a thing called copilot X, which is like a GPT chat window inside here, but I just use tragedy PT for it. Okay, in our last few minutes let's talk about the GPT chat. This is really that Genius in a Bottle code, but it does everything, so I usually start when you hear people talking about a message in AI. The message is not the place where you speak. The message is what you tell it and you're telling the AI ​​to work, so write me some Powershell that does blah and does it, that's all. I find it a good complement to the GitHub copilot.
I started using it first, so I'm probably the one who uses it the most. because I just got used to it too it's 20 bucks a month get it uh I use it Krista corrected you Chris corrected you in the chat she didn't, yeah and she said, "Okay, confirming that yes, thanks Krista, well throw me to the Wolves Julie, I'm pretty sure chat GPT is $20 a month, but if I'm wrong, Krista will let everyone know, so she'll fact check, but I use this, so obviously I use it for the code um but I use it for everything so our school had an event at the end of spring and a bunch of companies donated stuff I told the GPT chat to write them thank you notes and they did the event wrote a note of thanks to Acme because, you know, he gave us some widgets of what he did and he knew when I gave him the name of the event, he knew what school I was at, it was awesome, so I used it for everything, I get the 20 a month or so seven minutes after the first day of the month, uh, that school event happened before September 2021. it happened after, but the event had happened in the past and the school existed very well, so this is I would like that list so I can write to you everyone a thank you note to let them know that Todd wrote them a fake thank you note that I had nothing to do with, he actually wasn't as grateful as he might have seemed.
I'm very grateful, you know, this is something I did last week. Mark and I were working on something with a client and we were creating a Windows credential store for the client so that PNP could connect to it and we did it all. It took me about two minutes. I thought I should write a function for this. It's something I do all the time, so this is an absolutely real conversation. I have GPT chat. I said: let's write a function called add client credential. It has four tenant parameters. name, username, password and test credentials, you should use the ad PNP store credential to store the credentials and then I said I gave you the ones I meant before tenant.sharepoint.com uh tenant Dash Admin blah , blah and press Enter, okay, so One interesting thing here is two things to note from this number one: I didn't tell you what those parameters were supposed to do.
I just said what the parameters were and he understood that the first thing he did was, you know, tell me what. Those were going to do and that's the second thing I should know. Note that not only does he give me results of something someone else did, but I understand what he wanted and I understand what he is doing because he explains it to me and then gives me the code. so the tenant name is the tenant name like contoso and I didn't use contoso there like it figured it out on its own, so the image on the right is the beginning of that script, so I said, okay, that's cool and everyone less um just but oh, I messed up my uh my my uh screenshot here, so I said, okay, um, when, when are you going to add this credential, look and see if there's already a credential there.
I don't want to overwrite anything and it's like certainly and now I just added the thing to start with the code and you can see it on the right side now before it saves the credentials it tries to get the credentials and if it's not null it says Hey, do you want overwrite these credentials? Impressive, good job. I appreciate it, so I say, "Okay, that looks good." Now I want to be very understanding of the user running it if they don't enter a tenant name and all that kind of stuff. things ask them and it tells them no problem and it does it, but the other thing that's interesting was in the screenshots above the tenant name and the username and all of those parameters were required, so required equals to true, but now that you know you're going to handle that later, you changed them to failures so you could run your code, it did everything on its own, um, okay, so I had to add something to see if PNP Powershell was installed, tell them to install it if it wasn't there. so they do it um and then I said as I looked at it and I'm testing this all the time so it spits out the code.
I run it, it gives me more ideas, so now I'm running this and I realize. that he tells me thatIt's going to void a credential, but it doesn't say for whom, so I say, okay, you did that with the credentials. Now show me the name of the person whose credential is being overwritten, it's like no problem, it didn't come in. and you changed your code and you knew that when the entire credential was stored, there was a username property, so now it's showing us if you want to override that credential for blah Blossom, thanks uh

chatgpt

for that, and then I think I'm done, I'm like this. looks cool, write all my documentation for me and give me some examples and he did it, so you can see he wrote the feature, the synopsis, the description, all that, um and then as I was looking at it, I was getting really greedy at this point.
Like, this is great, but users can be dumb, so they can type their tenant name as contoso or they can type it as contoso.sharepoint.com or whatever, figure out all that and just do it right and there's no problem. This was fun because not only did it do what I wanted, but it had done it before, so I thought about it and it was like 10 lines of code while I trapped everything it did in one line of regex that Never in a Thousand Years with a Thousand Monkeys and a thousand typewriters I could have found the regular expression that did that and it just did it um in one line um and finally at the end I'm like okay we're all good what did I miss tell me some of the things I should check.
So he gave me this list of seven things and I have five of them on there, and then he comes back and then he just shows you the next slide, um then, and then he shows me the one that says, well, you know, I like those ideas, but I actually only want to do a couple of them, so add them and no problem and uh, and it did everything you say. you keep saying he says no problem, but he says certainly, certainly, yes, know your chat, GPT friend, yes, so this whole conversation, from start to finish, generated about 107 lines of code, something like that, this was about 10 minutes, this took me About now, I could have done all this on my own, it probably would have taken me 30 minutes, maybe I don't know, it was 10 minutes.
I said before that the reason I used this was because it made me write code faster, so I think that was probably true, less bugs, which I think is probably true, more functionality because as I went along I was thinking about more things. and there was no barrier to trying it, you just had to think about it and then the code was magically there. in better documentation so when I was done with everything I documented this for myself so I think it was delivered and I can confirm that that was how long it took because I asked him about this and then he came back in about 10 minutes and said. look at this and I was like what is that yeah because I sent him a screenshot and he was all blurry he couldn't see it he was just so excited he couldn't so here are some resources.
Sean Wang, is on a podcast that Julie previously linked links to chat with GPT and co-pilot. I did this with demos for the Power Platform Microsoft call here a couple of months ago, so you can see this with demos. Mark Andreessen, you all may remember him. What did he do? Netscape and Mosaic, uh, so he's part of Andreessen Horowitz Venture Capital, they're all involved in AI, so he wrote this great blog post about how AI will save the world and I agree with him, it's great and it's not I can believe it every time I practiced.
I was there for like 32 33 minutes and I can't believe I have it all wow, look at you one minute less and we're on the final slide, our next questions and practice episode is on September 6, let's talk. managing permissions in modern SharePoint and that landscape has changed quite significantly, so we'll probably have a lot of interesting things to talk about. See you live, so Todd and Mark are going to Seth and that will be in Stockholm, Sweden, September 11 and 12, I think. Todd, are you going to do this in a full session on this, yes, probably that hour long version, everyone should buy their plane tickets, yes, if you want to see beautiful Stockholm, which is my favorite place to visit, I think .
You should definitely go check out the New England Collaboration Days, which the healthy team at Praxis helps coordinate. That will happen on October 21 and registration is now open. The agenda is ready for all those good things. If you know of any organizations that would like to sponsor. we please ask them to contact us but that is happening so definitely consider having our local people sign up and join us live and also 365 educon in Chicago is October 30th to November 3rd and You can sign up for that Derek and I will be there uh. sharing our coding goodness so that's all we have for today there are some links in the chat um thank you all for joining us we hope to see you next time to ask and practice thank you have a great day bye everyone thank you very much for Join us this week at Aspen Praxis we love to receive your questions or session ideas which you can submit using the link about If you find this useful, hit the like or subscribe button and share this content with your colleagues.

If you have any copyright issue, please Contact