Coding 101 93: Powershell 4/4

neck ass you love from people you trust this is twist bandwidth for coding 101 is provided by cash fly at CAC ag/f ly calm this episode of coding 101 is brought to you by Linda calm the online learning platform with over 3000 on-demand video courses to help you strengthen your business technology and creative skills for a free 10-day trial visit linda.com /c 101 that’s ly and DA com /c 101 and by digital ocean simple and fast cloud hosting built for developers deploy an SSD cloud server in 55 seconds try it today for free visit digital ocean calm and once you sign up be sure to enter the promo code C 101 in the billing section for a ten dollar credit today on coding 101 it’s the Twitter API with PowerShell hello and welcome to coding 101 its the twitch show where we let you into the wonderful world of the code monkey the code warrior I’m father Robert balacera the digital Jesuit and of course joining me is my super special co-host mr. Lu Maresca he is a lead software developer at Microsoft Lou so good to have you back my friend how are things going up in the great land of redmond great to be back a lots of stuff changing around here it’s the year end and they think they just like to throw stuff at us so I’ve been very busy lately and as you can see Lou has kept his title as microsoft MVP wrangler and that is apt because we are bringing in two MVPs you’ve seen him before you’ll love them you know I’m that’s right it’s Sarah do kovitch and Adam Bertram let’s start with Sarah Sarah you are our code warrior but we decided to bring Adam in because you may remember the first module you did he was so helpful in the chat room and then he was so popular from the MVP episode that we just had to have ourselves some bertrand lovin how are you Sarah I’m doing great i’m glad i have Adam here with me because you know the past couple episodes i I couldn’t picture him without him he’s been awesome man he can also be a stronger voice today since mine is slowly coming back from laryngitis what did you do concert no yelling at kids oli wish i could say yelling at kids in this case allergies well Adam we bring in Adam Bertram because he’s not just a substitute voice for Sarah but also because he is a PowerShell MVP is not just a contributor to the world of PowerShell but he is one of its visionaries Adam thank you for coming back on the coding 101 no problem thanks for having me back Before we jump into the episode however we’re gonna be talking all about using PowerShell to access the twitter api for those folks out there who may want to do some heavy-duty automation i did want to bring up a couple of PowerShell centric stories this first one is something that i saw on my twitter feed this morning from a mr. Owen you may remember him also from our MVP episode about adding command ‘let’s that can access the MP io / gpio on Internet of Things device in Windows 10 go and bring up this article Anthony now I want to get I want to get your take on this Sarah Adam you both deal with powershell you both do a lot of automation we were speaking about this a little bit before the show Adam you were saying that there might be a way to do this with the current Colonel why would I want command ‘let’s on say my raspberry pi well sometimes whenever PowerShell is it has expanding a lot from the windows ecosystem and through the introduction of omi so you were right now you can manage network devices such as some switches and routers and things like that into various appliances and I don’t know anything about the Raspberry Pi in particular but I was thinking that if there was a ascend provider or that if the the windows 10 the Internet of Things addition provide us some kind of sim interface you may be able to use the built-in Simmons and says I get some instance or get sim session due to be able to remotely manage those things all right right and of course what they’re talking about is the version of Windows 10 stripped of the UI of course it’s just a smaller version of the colonel you have pins typically on Internet of Things gpio mpio that allow you to access devices out in the real world in this particular case a raspberry pi i can send either digital on or off or pwm sort of analog comparison signals so that i can control things like servos and relays and tip transistors in order to turn devices on or off or set conditions Sara this is

not a typical way to use PowerShell right i mean i know in powershell is used for automation we use it here at the twits to do at our TD desk it’s actually the thing that ingests the videos after we record every episode but is it a new way to think PowerShell as something that interacts with real-world devices I have not seen PowerShell interacting with hardware at that level before typically I mean we have a couple raspberry PI’s and Arduino is here at my house and we’re using things like C and some other languages when I use in PowerShell but if it were to go this route that would be pretty cool to see right Lou why why would I want to do this why wouldn’t I just just say you have Python on my rasp I because that does let me access the GPIO gpio what’s the advantage of doing it with windows 10 internet of things the things depends on what ecosystem you’re if you’re used to Windows environment and you want to maintain do device management using PowerShell you know it makes it easier for you just to kind of get that boot strap into the process I think so that I think for me it would be much easier for me to start going and do device management from IOT spurt perspective if I had to use Microsoft technologies like C sharp or in PowerShell and so that’s why I would say definitely jump into it I actually have seen this done working people using it to device manager you know whether it’s to generate you know backups of the device or to extract data or export data that kind of thing I’ve seen them use powershell scripts to do it so it’s actually a very empower phul environment especially for IOT devices all right Ryan well I’m gonna move on to a second story this is a very interesting article about when we should and should not use PowerShell modules now I we could just go around the horn here and talk to our panelist about well what are the good use cases but instead Anthony if you go ahead and show that link you’ll find that it was actually ridden by one of our guests today mr Adam Bertram Adam why do we need a checklist on when and when not to use PowerShell modules well when I found is the reason I wrote that article in the first place is because I found multiple instances where people would start writing scripts and they would write so many different scripts to do so many different things that eventually lost track of the scripts that they were building in the first place and also whenever they would go to share those scripts they would they would email it or you know FTP or Dropbox it or something but then it wouldn’t work right because there was some dependencies the script needed or some other thing it wasn’t a real good way to share it a module allows you to kind of group up similar functionality into a single it’s technically still just a script but it’s a PSM one file but PowerShell treats it as a single entity where you can catch a combined and batch all this different functionality and functions and code into a single file share one single file that does a lot of different things and then that way you can easily share it you can easily know where your coat is and that sort of thing as that sounds easy when you explain it like that it sounds okay yeah that’s exactly when you would use a module but Sarah we both know that this this is one of those tensions you have as you’re writing between just writings code just scripting out and then making that decision oh you know what this should probably be a module I’m probably going to reuse this I’m probably going to want to share this let’s find out where I should make my break points this goes into the PowerShell module what’s your criteria when do you decide that this piece of code now needs to become a module for me it’s one of those where if I’m gonna write code that I know other people may find useful such as creating a module to work with the twit TV API like we’re going to do tonight that’s one of those were that’s when I’m going to create a module another instance where I’ve created a module where I thought about is in so i created a published a book back in 2011 and in there i talked about providers and i created a module for that which allows us to access the i believe it was the document store and the other stores or the libraries through powershell it was something that it’s like you know it hasn’t been done may as well just create this so i can then redistribute it and it turned out to be a big hit from what my friends were telling me right um so yeah I mean it’s one of those it’s can I see other people using this and can I save other people time by doing it right right well there’s actually another aspect of this I mean yes anytime you want to share with other people anytime you think that your script might become something that people will want to install in their base code that’s always a good time to turn it into a module but Lou what about complexity because complexity is is normally in most languages that’s that’s my measure of when something needs to be broken out when when the script be or the function becomes so complicated that it’s it’s getting difficult to visualize how it’s interacting with the rest of the code yeah to me and no piece of code is too

small i mean but sometimes the use of the usefulness of a piece of code is overlooked the original developer but when they make it module like this and they make it useful to somebody else sometimes it’s more useful to them than anything else so there’s that whole open and closed principle that most development object or any development languages have where you you know it’s kind of open to extension but close to changing and so the idea is with when you build a module and c-sharp is you build it and then you give it out as a module and then to somebody can use it and then they can also extend it make it do other things and so that’s why they the whole principle mean can even be applied to power shows no matter how small the module and no matter you know if it does something even so simple you can I think Adam just answer the question I actually asked him a question about you have modules of modules meaning another module might use another module then then you become this chain of responsibility there and it makes it much neater to share and to kind of deploy so I think that’s kind of where most of languages come from when you break down tasks the smaller pieces Adam Lou tells us that no module is too small is he lying to us it’s actually a a question I still think about today i was just i just thought about that today because i had a script that was only maybe 10 lines long and but it was i had the potential to do so much more so what I was working on was a something to manipulate a ftp client actually and i had a you know a get get ftp settings command ‘let or a function i had a set ftp settings function and eventually i thought well if i just do a little bit more work i can actually make this into a really good module so good modules always have the the for the crud the typical developer cred methodology that create read update and delete so every good module is kind of built around a central object so in this instance if I was messing with a can I is ftp server a good modules functions would be get I is ftp server set is ftp server remove and and set or great now you get you get the point but that’s what good module is about is sort of similar to two objects you have your methods you’re sort of methods which are your your verbs or your get set update and delete and if you build it right you can kind of build it all around those that different functionality and really provide a really good piece of code to manage everything there is to know about a particular function I don’t want to spend too long in the banter section because we do need to get into some heavy PowerShell API wrangling but since we’ve got all our power shell MVPs here I do have one more story I want to touch on and start let me throw this to you first this is from the msdn blog Anthony if you go ahead and go to that link about PowerShell language support for Visual Studio code now why why why would I want this what does this give me okay so aunt the nave kenya sure my go-to meeting and key sir so this is Visual Studio code and if you haven’t heard about it so Microsoft has this editor to edit files of all various languages and it’s also available in multiple platforms so you can run it on Linux you can run it on Mac OS you can run it on windows so it’s similar to other editors out there such as like a timeo where you have cross-platform encoding but then take a look at this oh if it can there it goes you can see this is Visual Studio code and some of the code that we’re going to be looking at today we’ve got syntax highlighting we’ve got line numbers and I don’t have to worry about the heavy overhead that I might see you in say like an ISE I’m not loading modules I’m just writing code I can focus on code so the developer in me says this is nice because it takes out a lot of the noise it takes out things and I can just do this but I can also open other files so i could say something like okay maybe on a see maybe like a Python file so if i go to there you can see on that’s a boring python file but again syntax highlighting there um so what’s nice about having PowerShell individual Studio code is the fact that it’s something lightweight it’s something for me to work with and I can run this on my laptop right now which is running Windows 10 that is soon to be a linux machine I can run this on my new laptop that’ll be here in a couple weeks that will be running Windows 10 so I can run this on multiple platforms and my mac friends who give me a hard time about not having a man they could run too nice Lou what about it is this is this something that you can be adding to your to your desktop arsenal yeah i think i have owned so i have a macbook at home and I saw like what I like to do is sometimes I’ll open up a piece of code that send somebody sends me or links to and I can open it right in Visual Studio code and look at mighty sharp code it’s it’s it’s formatted correctly I can even make some changes and send it back I can use remote compiling in the cloud using the new

compilers of service I think there’s a lot of power behind Visual Studio code even though it’s a very simple unzip and use sort of thing so I it works really well with powershell to like Sarah was saying you can you can use it on windows and then I can just immediately jump over and be using OS X grant that they can’t execute the PowerShell scripts in uh no sex but again I can still edit the files and redeploy them to a windows machine if I wanted to so it makes it really useful so I think it’s very powerful and it’s very lightweight compared to just standard visuals to do you install that might take you 30 minutes to install so I think this is uh it’s a really easy package to kind of get used to last words to you Adam as an MVP is this something that you could see the PowerShell community embracing yes I have actually had a couple conversation with David Wilson the guy on the parasol team behind Visual Studio code and one of the questions that I posed to him was well how come you know this kind of came about my my original question was you know I at the ISE versus visuals to do code where is that going to go and he didn’t know specifically tell me but right now they’re working on both platforms so you will see more involvement in Visual Studio code and also some enhancements and improvements in the ISE as well Visual Studio code from the from what I’ve used of it looks it’s really nice it does nice you know you’re tabbing and a dent in your you know color highlighting and syntax highlighting and that sort of thing it’s a really nice tool i suggest you know anybody doing not just powershell but there’s a lot of different plugins in it that can do the same thing as well well lady and gentleman this has been fun but it looks like it’s time to head into the meat of the episode we’re going to using powershell to access the twit API but before we do that let’s go ahead and take a moment I thank the first sponsor of this episode of coding 101 now we like doing coding 101 we like doing shows on the twit TV network where we get to teach you things but we understand that we will never have enough time to give you the in-depth look at the topics that we bring up yes we can show you what a programming language looks like yes we can show you how to assemble things on know how but when it comes down to it you need a place that has a repository of knowledge a place that you can go to to reference and that place is Linda calm Linda calm is for the problem solvers it’s for the curious it’s for the makers for the doers for the people who want to make things happen maybe you want to learn how to develop an app or take better photos or sharpen your Excel skills well lynda.com has everything that you need to feed your curious mind Linda’s latest courses include iOS 9 app extensions developing Microsoft’s sequel server 2014 databases and techniques for developing secure software which is taught by mr. roo-roo a Penn State faculty member teaching cyber security and information technology in this course he’ll teach you how to analyze and avoid different kinds of security threats design secure software and use best practices to secure your sensitive data this is the kind of knowledge that you get with Linda calm it’s both reference and information that stretches your current knowledge base with a lynda.com membership you can watch and learn from top experts who are passionate about teaching you can stream thousands of video courses on demand and you get to learn on your own schedule you can take notes you can make a playlist you get to well design the courses for you rather than having it done the other way around I really love the fact that they’ve got course transcripts because course transcripts means that if you have a specific question about say a subject that you already know but you’ve forgotten a few bits and pieces that you might need rather than sitting through an entire lesson you just jump straight to that part of the video that answers the question that you have that’s what Linda calm lets you do have immediate access to the knowledge that you need oh you can also share your playlists with friends which means you can ask your friend your friends your community to join you in your love of learning folks if you like knowledge you’re gonna love Linda calm you’re lynda.com membership gives you unlimited access to training on hundreds of topics all for one low flat rate whether you’re looking to become an expert you’re passionate about a hobby or you just want to learn something new I want you to visit linda.com /c 101 and sign up for your free 10 day trial that’s Linda calm ly and da calm /c 101 and we thank Linda calm for their support of coding 101 let’s get back into the action Sarah when you last left us we were just starting to play around with powershell modules we were just starting to look at the the different well functions and features that we could access including destroying our computer’s registry but now we want to do something more constructive we want to access the Twitter API what’s the first step first stuff is looking at the twitter api documentation and there’s a reason why i say that so let’s go ahead and flip over thank you so the twit TV api is very well documented over here on

the slate apiary oh so we’ve got the links here that will make sure are included in the show notes but while i was looking at this for our episode there are a few things that i wanted to do for you I want to get you guys started with creating your own powerful module I want to make sure you guys have two different functions to work with functions that take in parameters and functions that don’t take parameters this will give you the starting framework for you to expand upon this module for your needs so this is just a little teaser I hope you got so do your homework afterwards um so when I was looking at this list go back to the API list I was looking along this left-hand side here to see what some of our categories are whoa Miriam back there we go and so I was looking at specifically I figured well let’s do something with the shows and episodes let’s take a look at the list of all the shows that are available in twit TV plus any episodes for a particular show so let’s go ahead and create this now before we get into creating our module whenever I create a module and I have an API there are a couple things I’m looking for in the documentation what is what are the endpoints to what do I need in order to send to it I’m going to scroll down and see that my endpoints first I have to use HTTPS and then I see that they have an example here so I’m going to close this sidebar and look at their example so basically what the example here is showing is that I have to send some headers just send some headers including my app my app ID my app key which i can get to I get those assigned via the URL i post in the chat channel and then I can call an end point and end point is basically a web service that exposes a little give me back data if I hit it properly um there are other things in here like error messages stuff like that but we’re going to actually just jump into writing code a little bit so what I’m gonna do is I’m going to start the PowerShell ISE so basically if you in Windows 10 i can press start and type is e and that’ll start it up i can do that and see what it does oh that guy starts low funds i’m gonna close that guy and openly a guy I’ve got the font check already done on they should be able to see can you guys see that okay text boys oh yeah how we can okay it’s the miracles of the TriCaster thank you guys alright so as I mentioned we were looking at the API documentation and we noticed a few things to do so we need to get our app ID in our app key I’ve already copied and pasted those into a file that you guys don’t see on the screen I’m willing to copy and paste them here so you guys can see what I’m doing so I’m restoring these in variables no to appease Adam I’m gonna change these two single quotes yay now there’s a reason for that and Adam and I were going back and forth about single quotes and double quotes this afternoon a basically powershell that there’s double quotes powershell can manipulate the string if you put variable names etc in there so so Keefe is powershell 9 happy this is what we’re going to do and we did mention that the API needs to have a particular header so we’re going to say that first of all it has an what we call next step tender and this is the particular Matt that it needs and then what I’m going to do and I’ll let Adam tell you a little more of what this is we need to get our headers and package them up so Adam you want to tell them what’s going on there what that is sure well what you’ll see down a little bit farther is that headers variable there is needed by a the invoke rest method command ‘let and that invoke rest method man that has a believeth as the parameters call headers and what Sarah sent me this coat before before the show and we’re going over originally she had was using a dotnet at I called a devii method of OT where she would create a dotnet object a dictionary object and then would add the the keys in there and it worked I’m sure it worked fine it’s just not something I was used to seeing and I thought you know a hash table is almost exactly like a dictionary object in PowerShell and somebody that’s not a developer such as myself an IT pro probably wouldn’t understand what she was doing so I thought more an easier approach would be to use a hash table and put the keys in there so that’s what you’re seeing there in that header is variable nice okay we’re gonna destroy this key later on so uh yeah yeah don’t yeah yeah no that’s fine these guys have been have been warned before so yeah and what’s nice

about a hash table is that it is simply a key value pair so it is simply this is mikey this is an except this is the value I except expect in there this is about the key for the app ID we’re going to take a look at how this gets sent over hold on all right so like I had mentioned we looked at the API and I saw stuff about episodes and shows so this is what I’m going to do I’m going to create two functions noticed when i type function going with the PowerShell naming I want to make sure since we’re getting things back and I’m just going to do get ash and then i’m going to put in because it’s twit I want to make this so that this is a recognizable name I’m going to do it like this I’m also gonna do a function for episode so this is when I’m creating modules and looking at end points of an API for example I’m gonna look at what do I want to extend and I’m just gonna create these functions just these placeholders okay it got time alright so now what I’m going to do is uh sir when you’re mapping out the logic for for your script is is that how you do what you use the placeholders to remind you of K this is I want the use particular models to do these particular things absolutely absolutely somewhat i actually do is not only do i put these functions in here but I go so far as to usually say something in comments so I’ll say uh gets list of shows on twit TV and then well say here is I’m going to get list of episodes for a particular show so I actually put my goals in comments when I’m starting out whether i’m doing PowerShell or C sharp or any other language when i’m working with methods like this i’m putting comments and there to remind me what exactly was i intending to do with this makes sense that absolutely makes sense all right all right no what’s that yeah it’s called pseudo code and so basic and it’s something that working with my apprentices at the software guild we encourage you to code we tell them if you can’t solve the problem in plain English you’re not gonna solve the problem in code we have to be able to solve in plain english first you have to be able to do this well it also it just helps you when you’re finally writing that function if you if you have the recall to your place holders to your pseudo code you’re like okay that’s right it needs to do this this is this the limit of the scope in fact I usually go a step further and not only do I give it a general description of what it does I’ll also give it a bit more meat to say okay I don’t want it to do this that will be handled by another function because as it gets larger and larger and larger it becomes very confusing yeah yeah all right what’s next okay so next we’re going to actually put some content into our get twitch oh and I’ll Adam talk as I’m putting this in here want to talk about about what command lip binding in for a Mar and these are the empty ones oh sure in PowerShell you have two two kinds of functions the first is a basic function and that’s what you just saw before before Sarah put in the commandment binding so a basic function is just you have the function declaration and then the punt name of the function and then your curly brackets that’s what a basic function is and that’s what you would think of as just like a function in any other any other language that the you know are familiar with however PowerShell has this concept of advanced functions and an advanced function is it mimics an actual built-in compiled command lit so if a developer to come in and see sharp and develop a command lit a binary module which we might discuss here in a minute that that gives you a lot of power and flexibility so you have a lot of debugging things you can do in it somewhat if support you have a lot of confirm there’s a lot of different parameters and then you can do that functionality to come built in if you just build an advanced function and the in order to build that advanced function you need to just have that that commandment binding keyword there that sarah has with the parameter and that actually right out of the box gives you advanced function capabilities all right thank you sir and right now online 19 we’re looking at the invoke rest method command ‘let what this is used for is to call out to restful services so services that will usually give us back XML or JSON um and so it’s gonna call out there and say hey go to this URL at this endpoint and by the way I’m including these headers that we declared up a pub so this accept this app ID this app key

so is this is going to do is just going to go straight to this endpoint and get all of the shows that are available on twit.tv which is fine for what we need now how was this handling storage everything is going in memory at the moment because I was just thinking I eventually someone’s probably going to want to use PowerShell to drive the backend for their twit app powershell would be a nice way to sort of brute force just have simple command automation to go to the twit api every minute or hour or whatever it might be and pull down episodes pull down updates to our programming and then store it somewhere else not in memory so that it can be persistent for clients to access now we don’t to go that to that now but is that relatively simple in PowerShell I would think it’s doable I don’t know to what degree of simplicity though Adam you look like that’s not the way you’d want to do it well no I’m not I’m saying it’s simple is a relative term definitely yes it just depends on what what the API comes back you know is it gonna be a container that has you know uh is gonna be an mp4 and mp3 really if it just comes back with just a file like that really it wouldn’t be that difficult you would just bring it down and then you could just save it as whoever you want wherever you want on the file system well they would even have to save the mp4 so I mean basically all they’re doing is they’re saving the links and then the clients can access directly off of our content oh yeah that would meet the Athenians yeah yeah so it’s not a lot of data I mean it’s basically pulling down JSON blobs and then sorting them out so that they don’t have to continually hit our API and one of the things that we’ve done is our API keys are limited to I Patrick delehanty will probably correct me on this I think it’s five queries per minute Patrick shout from your office if that’s right and and then pass that it will you’ll time out until you you hit your next allotment so we’ve been telling people you cannot build your client you cannot build your app to hit art with API with your API key that’s a horrible horrible idea but if they could automate a way to just have those downloaded to their server that works I mean you could use you could technically use the with the file out module whatever in PowerShell just write the JSON directly to disk but not necessarily the best option because then you’d have to load those JSON blob sup every time you wanted a kind of quarry through them so it’d be kind of tough to do so you might want to store to something else other than just a flat files right right okay sorry I digress too much take us back in Sarah already so now that we have a function created a advanced one of course now we’re going to do something a little more important that always gets lacking and that’s add some help to it because documentation while it gets overlooked is actually pretty crucial so what I’m going to do is I’m going to copy and paste a big chunk and it needs to go before this command let binding Oh like that see it one copy over awesome so just you guys can see how this works so we’ve got the less than a pound in a ends by a pound integrator then this is what they call a um comment based help and there will be a link to that in the show notes as well um and it’s also in so this module is available for download and you’ll have that link as well so you guys can see the link to comment base help but basically what this shows is schnapps is a description um inputs and outputs are you to somewhere I haven’t figured out just where yet so I put a lot of that in the description and then a link and so I’ve linked to the end point that I’m calling that way you can get more description about the objects that are coming back rather than me have to write that documentation somebody already did thank you to ever wrote that so just go to that link instead partially that’s Patrick delehanty you won’t take credit for it but I’ll give it to him Oh Patrick rocks but we already know that cuz he’s been on the show quite a few times did absolutely okay so now here’s here’s actually a question I had about PowerShell we have been showing people how to access the API through say C sharp which is nice because it gives us the ability to get that JSON blob back and then run it through a a json parser of what’s the process for doing it in PowerShell because that that sounds like it might be a little bit different so getting back the JSON and what how to handle it with powershell right so everything i love powershell for this and that everything comes back as an object and so we can manipulate it with objects I after we create these I can show you what that looks like coming back or I can technically and a lot

let’s do this my import module Twitter API since i already had the module pre-written just so you guys can see what comes back so i’m gonna create a variable shows and i’m gonna say i get twitch show and press enter and we’ll take a look at what shows looks like i shouldn’t like that let me do it that way so it’s taken this time it’s it in the API if you guys gonna cry cuz everybody’s gonna hit me mhmmm if I stored it in a variable so that way I could actually say okay shows and if I press ENTER notice this is what comes back from the API okay yeah so you are you are getting the pure JSON blob and and it’s got it tells me it’s a number of shows and then I have all the shows in the show’s blob now what’s nice about partial is I can do something like this so I’m going to bring up my command window a minute and salt there’s no quick that’s called a what they call that though that’s called a representation object what is a actually called that that’s representing the JSON blob this is probably just a general powershell object what that’s what I can do it is do dollar sign shows and I want to pipe it to get number so if you guys remember in the earlier episode prolly episode 104 or to a foreign power shell one of the most useful command lets to know is get member what this does is this will tell us all the properties on that object so if i press enter you can see that this is the type it’s called a PS custom object so what powershell does with the JSON object is it tosses it into its own custom object and it uses it has stuff under the covers apparently that can read it and what we see things like there’s the count property there’s a shows property I can take this one step further no watches i can say shows dot shows pipe get number and yeah and spelling out get member you can dude sgm the reason why I do get members felt I was cuz while you guys are still learning this is 101 right now when I do get member you can see all sorts other properties free show you can see that there’s a label you can see there’s an ID that’s nice about the definition as you can see samples of values so you have a little idea of what you’re pulling that’s actually that’s very very cool i like that oh hey Lou why don’t we just do this we didn’t really use that JSON parser don’t we wish every language has JSON or project very tight very insulting to it right now let’s make it clear Sarah that’s that’s built in the PowerShell that’s not that’s not a say that you wrote no that’s all I said it’s doing something under the covers I will leave it as its magic because i personally have no idea what they’re doing so know if adam has some you know it takes the JSON blob it puts into an object and then you can it just source it for you inside that object you you can absolutely and I can do all sorts of inhalation if I could do all my JSON work in PowerShell and get rid of like JavaScript and C sharp and Java I would gladly do that because this is so much easier okay I was kind of joking about making a back-end server with powershell for libya no i actually want to see someone do it Adam oh it’s already been done oh okay never even had that they convert from and convert to JSON so if you have a PS custom object and you can easily just convert it right to JSON or heard it from json back and forth without just a function that’s ridiculous instead of having to parse the JSON into individual fails this keeps it as a blob it keeps it as an object and then I can modify the object and push the object back out as a JSON blob mhm yes let’s do that let’s do this all right I want to continue cuz we got a little bit more to go on the Twitter API but before we go let’s go ahead and thank the second sponsor of this episode of coding 101 now you’ve heard me talk about digital ocean before it is the easiest way to get up and running if you need to host a project if you need to put up an if you need to put up a back-end service you get to put it into a droplet a droplet is a tiny little virtual server that pretty much lets you do anything you want with root access but did you know that digital ocean is also a really good place for people who just want to start small projects want to push up a wordpress blog you could do that with digital ocean want to play with Drupal you could do that with digital ocean do you want to play with creating your back-end for your twit API app you can do that whether you’re an experienced codewarrior or you’re just getting started you do need flexible reliable and affordable hosting we all know that well digital ocean gives you that with their droplets and because they give you full root access that means that you don’t have to spend a lot of time tripping around the restrictions that are placed on you it’s built for developers by developers and it’s used by over 400,000 of them including me you can deploy and configure your droplets via a streamline control panel or a simple API and you get to choose your OS Ubuntu sent OS Debian fedora core OS FreeBSD they’ve also got a one-click install that lets you quickly deploy

apps like Django docker Drupal lamp get lab mediawiki nodejs wordpress ghost Magento own cloud Ruby on Rails and more all their servers are built on hex core machines with dedicated ECC memory and raid SSD storage and the servers can have up to 20 CPUs 64 gigabytes of memory and 640 gigabytes of SSD storage space so you know it’s scalable now they’ve got auto backups and snapshots so they’ll take care of all that scut work the stuff you don’t want to do you just have to worry about deploying your app and making sure it’s as good as you want it to be they give you full featured DNS management with html5 + ssh SFTP kvm VNC for virtual desktops ninety-nine point nine nine percent uptime and gigabit speeds around the world all of that’s great I mean that’s the technology and the technology behind digitalocean is impressive but what I really like is the fact that they’ve got a very strong and active community a user base people who do this for a living who depend on digital ocean for their livelihood which means you’re going to get real world answers to your question folks there’s really no reason not to use digital ocean you can deploy your SSD cloud server in his little as 55 seconds now digitalocean has incredibly affordable in straightforward pricing which server starting in just five dollars per month there’s also hourly pricing available and in case you want to stand something up just for a while to see if it’ll actually exist in the real world it starts at less than a penny or an hour but we’re gonna make it so that you can get started today and deploy your SSD cloud server for free that’s right for nothing visit digital ocean calm and create an account once you confirm your email and account information go to the billing section and enter the promo code c-101 for a free ten dollar credit that’s plenty to get started and explore what digital ocean can do for you that’s digital ocean calm digitalocean dot-com and once you sign up enter the code C 101 in the building section for a ten dollar credit we’re back with sidhu key that’s right it’s sarah and adam who have just well they’ve they’ve made me question why I haven’t been programming in PowerShell all these years I missing out pondering them I’ve been missing out but Sarah can’t keep us going so we just we just learned how incredibly efficient and how well powershell handles JSON blobs well what do i do once I’ve got that block okay um so once you got that blob you can do whatever you want with it the again that was my shows uh shows that shows is a bomb this is all the information I pulled from the API and this is just from the commandment that we created just so you guys know this is what this does so pretty cool for us at this point we can extract the data and do whatever we want with it um whether it’s pulling out text and writing it to a file to play with later whether it’s pushing this stuff into a database whether it’s pushing it into a database and then having a website pull that information live just some of the many things you can do um but let’s go ahead and let’s so this was we looked at command light with just no parameters I want to show you guys how to create one with parameters as well ready to to jump into it jump in alright so this function get to it episode I’m actually going to take these parentheses out so like I said when I was laying out the the whole idea of this module I create the placeholder but we got to say a little bit more here okay we got to add a parameter but because we’re doing Adams cool fancy way of advanced stuff this is how it works see ya again we’ve got all sorts of code coming in ah so I want to put that in here pace that scroll about so you guys can see it let’s get down a little bit make sure there we go auntie’s panty so this is get Twitter episode again there’s that command lip binding only this time now lying’s 45 to 49 hour hey we have a parameter line 46 is our way of saying that you have to include this parameter you can’t run this command lit without it it’s validate not in all our empty is to make sure that the show ID is not coming in as an all our empty thing it better be filled in and 48 says oh yeah by the way this is a number this is an integer that we’re looking to see here so this is how i specify parameters in our functions for our command lights so if i had multiple parameters i could go ahead and put them in here but this particular example I figure okay we’ve got a list of episodes for a particular show and so that’s what I’ve got here so we’ve got this invoke rest method we call what’s nice about the API is you

have all sorts of filtering and you do it all within the URL this is all going through get uh so filter shows show ID again there’s those headers that we used earlier no just like last time I also want to see help files or help text because again documentation is key so this me this module right now is running here on my desktop you guys when you download my module onto your machines you’re gonna be like well how does this work what does it do so that’s why we put help in there and I’m gonna paste this right above my command not binding now we’ve got the same thing with our synopsis we’ve got our description inputs and outputs again I put them in there could i imagine something’s going to use it but then we also have examples we’re gonna take a look at what this looks like here in a minute but just so you guys can see what it looks like in terms of code this is what we’ve got so I’ve got a sample of how to call the command lit with the parameter and a specific parameter ID this is the ID for coding 101 and I could actually run this guide on here so you guys can see what this looks like I’m gonna clear this screen out there we go and when I run that it’s running as we can see down here below notice there are 93 episodes of coding 101 nice last one was PowerShell 304 and so again just like the other end point we’ve got a count then we’ve gotten object so I could do if I did the same thing here or I’ll tie said episodes equals your twit I can do tab completion a more tab completion that so if i look at episodes episodes uh there’s frost feather you guys can see all this stuff scroll I and there goes this is all the data that’s in that in an object for coding when I want yeah it’s looks so neat I losing my seriously I’m still losing my mind over that hi this is her shoes Oh what was your life like Lou why wouldn’t we doing this before oh wow and I’ll just saying I can modify that object any way I want oh sure sure once it’s in tier once you store in here you can do whatever you want to it you’re not gonna change anything on the server these are all just gets it says give me data we’re not pushing anything back up there but yeah this one way too late there’s a Padre just said was a you double up your own API you can bring it down and then modify a little bit of and present that in a different way to the users of your own custom API here right I’m trying to think about how that works so if I got if I got powershell running on my back end I’ve got these JSON blobs coming down into these objects I have every way to modify the object I want and then I can push the JSON blob back up to my own website and that’s what my clients hit mm-hmm mm-hmm okay yes uh dad took like 16 different steps that I was gonna do out of the way thank you why not just build a web server out with powershell is pretty easy way connected i can do that i did i do so i could do that really I I can do that you can do that I could just serve on those days I’ll blobs yep directly okay now i really want command lets on a raspberry pi i want to see if that can handle it well I mean that’d be a server actually that would be an incredible project make this this becomes the server for your twitter api it’s just use of PowerShell command lets to pull down those Jason’s and then serve it up to whoever I want I expect I don’t get help by next week okay well I got I mean I I may be in a turkey coma but that’s something I’m never gonna work on I seriously I’m speechless I had no idea was this powerful I mean people have been telling me for a while that power shell is it’s powerful and I see it because we’ve been using it here in the twit TV studio for automation for process automation but I had no idea it could do this let Lou seriously I take takes talk about something cuz i’m wrapping my head around this talk about something so one thing that the powershell will continue to do is is continue to grow and get more powerful i think like like adam is saying you can you could write their own web server soon you’ll be able to run devices soon you’ll be able to control containers and you know deploy things and you know build out docker instances and so on so forth so I think you’re starting to get to just the beginning have how powerful powershell is so I think it’s really good to get the insights into what the fundamentals are and then just try it yourself I really want to see Adam can you can you give me a bit more of a

preview on using PowerShell with containers because that’s that’s the big thing right now once we get the security sorted out can Tanner’s is where all of our data centers in fact all of our home appliances are going to be headed you want everything in a container because it could run on basically anything what what will I be able to do with my containers using PowerShell well right now it’s so early on you can do a few things I mean you can’t I’m not real familiar with the support but I know based on the content that I’ve read and what I do know about containers is right now you can support you can manage docker containers you can manage hyper-v containers you can do a lot of different things with with powershell now especially with Server 2016 tp4 i think is out now that’s that’s the primary way so you’ll see that same thing goes with like how office 365 was back in the day you know before before the GUI they had PowerShell commands do everything and they slowly started adding more gooey support for more things that’s what you see with containers so you’ll see a lot of PowerShell support at first and then once they have the PowerShell support then they start adding on GUI features and things to better manage the the containers and the whatever the product is Sarah uh seriously okay that actually looks really really simple we’re gonna make all of this code available right your scripts will be available we’ve been having difficulty so what I’m gonna do I’m just gonna use your link we’re gonna make sure your your link is in the show notes so can I sit down those this directly now let me ask you we’d like to send people home with a little bit of homework what what do you want to see them do with your script I want to see them add more add more command lets using these as a guide I have one more two more things I have to show to wrap it up right right before we do it but yeah your homework is going to be to expand on this now we’ve got a command let with parameters I command that without parameters and consume all the api’s start with twitter api and go from there all the api’s all the api’s so to my last two things the first one is this export module member dash function get their start what this allows us to do is it says hey I’ve got a module of things like for all of the commandments a target dashed are that way we can use everything that’s being packaged in here and then the final thing what makes it a modules when we do the save so if I go up to file taught save as I’m going to save this in my coding 101 Twitter API folder which I know is I’m IEPs modules I’m just gonna call this to add API to the reason why i say twitter api to is because while twit api one is the one that’s loaded in working I don’t want to kill that but if I save it is the dot p sm one that is a powershell module file and that’s what makes it a script module right right save it no now that that’s saved you should be able to come into here i’m gonna clear this to give us some room get module ash list available we talked about this in a previous episode so this is gonna do its thing scan the computer find all the modules that first time you it gave us a ridiculously large list i think this day yeah you use you cut it down so we’re not inundated yeah yeah and in this case I think it’s just not seeing my twitter api to a twitter api and 20 pi/2 are probably showing the same kind of deal right right but it should appear here and then you can do import module twitter api and just so you guys can see how the help files are there i just wanted to show you guys at one more time so you can see so i can say get help get a loser twitter sodes what episode if i press enter so all of our commands look they mapped onto something like this or you can see their synopsis there’s syntax there’s description related links all there this particular one I know I can do get help ash twitta sowed dash examples and press ENTER and you can see my examples the formatting is a little off because example 2 has multiple lines to it but it talks you through the steps for how to get all the episodes for coding 101 Adam and I again we’re talking about the double quotes and single quotes you could also use single quotes there for coding 101 it’s just I come from a world of languages where single quotes are with characters double quote through strings so sometimes I can’t shut those behaviors I don’t know Sarah I’ve heard that wars have started over less than single quotes versus double quotes so semicolons and curly braces start worst Adam is there anything that you want to add I mean I thank you very much for bringing this to us I I cannot tell you how impressed I am I wish we had started with this as a first language on coding 101 because this is this is something that everybody has if

you’ve got a windows box you’ve got power shell on it right now what what bit of advice would you want a hand to the audience who’s going to be taking Sarah’s modules taking them home and trying to access all the api’s well the the first piece of advice I would have would be just like Sarah said the how you learn anything is with especially with PowerShell just tinkering around read the documentation see what’s possible since the API uses and you can do a lot of filtering with the URLs what I would first do is try to mess with that create functions that build various URLs you don’t have to run invoke rex rest method once you have the string with just a URL and it in the properly properly formatted with the proper parameters in there then it’s just a matter of passing that to invoke respite because it does all the hard work so I think I really the next step what a really good next step would be would be to create a set of functions that just build various strings just the URLs that you can then pass right to invoke receta to to grab whatever you need fantastic lou is there any wisdom that you’d like to impart i mean we unfortunately we’re going to be losing our our MVP so you will no longer be the MVP wrangler but before we send Sarah and Adam off into the PowerShell ether of what what do you want the audience to keep use the PowerShell MVPs for information because adamant Sarah awesome awesome uses of them from every information about power so so feel free to reach out to them they’re always there active on Twitter and they’re active on like Adam has a great a great blog post about PowerShell so if you’re just still learning and you want to learn a whole bunch of other things it’s always good to reach out to the community and I just try things out and also one thing to add to the homework is find a way to store the JSON blob so you can just no you can keep picking it back up and reusing it and be going out to get different shows at different times that kind of thing that would be also a useful module to build folks I’m afraid we’re at the end of this episode of coding 101 I’m still a little bit stunned I did not expect it to be that simple I did not expect to be that easy but it is I want to thank so much arco code warriors Sarah do kovitch and Adam Bertram Sarah of course is at sidhu key at s ad UK I e on twitter follow her she’s the owner of Cleveland tech events an all around good person you know what we have to see you more on the twit TV network we’ve gotten such good response people like you people love the fact that you you know your stuff and even though you like double quotes even more than single quotes I won’t hold it against her nice we won’t hold that against a can’t help it is is there another place that you would like the audience to go to to to find your work um besides on Twitter you guys can follow me on coding geek at calm that’s why i blog about all things going on my life whether it’s technical or with my apprentice is or what other craziness I may run into maybe I’ll start a single quotes versus double quotes were there wait this could be a holy war and of course hahaha Adam Bertram who is twitter.com slash add Bertram ad be ERT r.a.m he is a PowerShell MVP we I’m sure we will see him again on the twit TV network but to where can people go to find your work well other than Twitter I’m Mon Adam the automator com where I blog about just about everything automation in PowerShell yeah there you go and finally of course Lou Maresca Lou I wouldn’t want to do coding 101 without you you it’s always so much fun everything you bring to the show where can people go if they want to find out about you about CRM dynamics which is the Microsoft team that you’re part of or what you’ll be doing this holiday season well gonna be expanding on our what do we call it last year our little helper or santa’s little helper application so we can get some some deals for black friday so check out that see the c-sharp module that we talked about I don’t remember what one name what number it was but it was a great module about basically went out all tailors and pulled all down all the the prices and I was able to store the prices and stuff so I’ve been expanding on that to find all the deals to see this year so that’s what I’m doing for this week but you can always find me at on twitter at lu mmm and of course all my work on crm is ciara and dynamics com folks that’s how you know a real geek he doesn’t go to black friday he just programs a service to do it for him powershell powershell our stats we shall I wonder if we could do Santa’s Little Helper in power that is that might be fun how mighty for that is lose homework that it is Lou you now have your homework folks we want to thank you for joining us for coding 101 don’t forget that we did this show every Monday 230 p.m. pacific time it’s well at live that twit.tv if you watch a slob go ahead and jump into the chat room at IRC twit.tv it’s a great way to talk to us during the show get some feedback and maybe interject your own opinion into the the episode in fact that’s how Adam Bertram got onto these episodes he was in the chat room for so dukey’s first episodes

and we thought hey you know what this guy needs to be on the stream also don’t forget that you couldn’t you can go to our twitch Oh page at twit.tv / code what will happen there is you’ll find the links to subdue keys a module so if you want to download it I’m gonna make sure i’m actually going to do it myself make sure that the link goes in so that you can go straight in and download all the code that you need you don’t have to write it from the screen finally I want to thank everyone here at the brickhouse who makes this show possible of course to Lisa and Tulio and my TD who today is Anthony Anthony can you say hello to the everybody now Anthony what do you do here oh just a little bit of everything TD editing graphics you name it am a little dark and is that in the dark until next time I’d father Robert ballast air this has been coding 101 and Lou how do we end every show and the vine