Writing Award Winning PowerShell Functions and Script Modules by Mike Robbins

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so so welcome we're going to be presenting writing award-winning PowerShell functions and script modules in here today and I was going to present this at a sequel Saturday in Nashville earlier this year and there was ice so I didn't make it up there but I posted it on reddit and you know how you have a lot of people you get a lot of comments from jerks I'll just call them jerks on reddit and one guy said well you didn't say it was a good award it could be the worst script the worst award so but you want hopefully this will prevent you from getting the worst award and I'll tell you a little bit about me you're not here to learn about me but who in the room does not know who I am okay good I think I've done my job of branding them pretty well so I'm Mike huff Robbins I'm a Microsoft MVP I used to be a PowerShell MVP now I'm a cloud and data center management MVP we all got rolled up so like Turk next door he's a he's a cloud and data center management MVP also as I previously said I run the Mississippi power show user group along with Ron Edwards and I told you guys already that I wanted to advanced category in the scripting games in 2013 well Ron Edwards the co-founder of my user group won the advanced category in 2012 so we're the only user group with back-to-back winners of the scripting games and when Ron wanted it Wilson was still running it I've authored or co-authored a number of books there's links in the slide deck and all this is on github already and the USB keys that we gave out the windows powershell TFM fourth edition is this book here that me and Jason Hill met co-authored it's got the full version on there I already mentioned about the scripting games you can learn more about me at my cup robbins comm you're not here to learn about me but one thing I will tell you about my blog is I've been blogging about PowerShell since 2009 so I have over 500 blog articles and I put all my code on github now I started doing that and what I do I won't go back and update the blog articles but I'll update it on github until you go out there and get the latest version and just to give you an idea the type of content I have I get over like 600,000 hits a year and one of the reasons I do that I mean I'm selfish I do it for myself I can't remember how I did something later down the road but then also if you guys would enjoy the content then it's out there one thing also I get a lot of peer reviews because I will post it on reddit and you get a lot of trolls out there that but listen to what they have to say because like one of my videos I put on YouTube I got some great feedback and then one guy comes along and says hey it would be great if you would stop bumping the bike and I was like what a jerk you know but then I went back and listened to the video and he was right so listen to people if you guys saw Lee Daly he won one of the awards yesterday and I don't know Lee Daly but he has commented on some of my post on reddit because a few weeks ago I posted some code where I was splitting a path and I did it with a regular expression and I just wrote the code I never even thought about it and Lee said hey is there any reason you're not using split path and no I just never thought about it so I went and updated the code and gave him credit for it so that's the sort of things I don't have it I'm the advanced person at work and all those I have some other guys that write some PowerShell and I will let them review my code I generally don't they wouldn't catch something like that is what I'm getting at so if you want peer reviews it's a great way to get it by blogging your code okay we're gonna skip through some of this I know all you guys are either an IT pro a developer or somewhere in between when I tell the IT there the Otzi frozen my shops say you're not naughty praise your developer and then I go over to the to the developers and they say oh you're not a real developer so I'm somewhere in between I'm sure you guys are too so who's using unit testing today like pester okay good what about source control great I would say out of those two the source control is more important than the unit testing and that gives me an idea how advanced you are because if you're using bait though than your your more advanced but if you're not then you're less advanced is what I would say because if you start writing code that you value you're gonna put it in source control the unit testing it helps it can cut down on the time who's using BS code today Visual Studio code awesome and I'm kind of like this guy up front here I'm like this you know I used the best tool for the job at the point in time I won't be using BS code today in this session I'll show it a little bit I've I've been using it for about a year now pretty heavily it's the I generally don't open up the IC but there's a couple features in the IC since I've been using it for about the IC for about eight years I feel a lot more comfortable up here in front of a hundred people using the IC and let me just say this so Visual Studio code is nothing like Visual Studio Visual Studio code is free that's a misconception I've heard it is very lightweight it's almost like using notepad it's that light where if you install Visual Studio on your machine it's very heavy and bloated and if you take the defaults it install sequel server and everything but the kitchen sink so anytime I install Visual Studio I install it on a VM because I don't want all that garbage on my machine and I'll use Visual Studio so and frequently I don't want I don't want the slowdown so I assume that if you're not using BS code you're using the ISE and parish else to do is another option I write my gooeys in that but I I typically do not use that on a day-to-day basis who is using powershell core ok good and one thing about PowerShell core there's actually some notes in the slide deck I don't see the notes so if you want to see the notes just download the PowerPoint I don't think they're in the PDF copy that uploaded PowerShell core is not a replacement for Windows PowerShell it installs side by side on a Windows system and everything is totally separate even if you update your help and Windows PowerShell you don't have the updates in PowerShell core you have to update it there too there's a module you can install too to put the C program vowels Windows PowerShell module path in your in your PS module path for PowerShell core and I know that sounds confusing but what it does it allows you to use your Windows PowerShell modules and PS core it just gives you a pointer and I'll show that here in a minute how many power show experts do we have in the ring Soyoung great we have one so I invited Joe Bennett he's not here to come heckle my session and also Jason Helmick so I did Windows updates this morning two reasons Don Jones told me not to do them inside did him and they were available so I said I'll head off the problem and do it but that's the benefit of source code I told the story a few minutes ago I'll be brief so I committed my code to github because if I host up my machine I could say hey is somebody in the audience got a machine I can present only and I could just pull down my code and present so this is what you want to try to avoid this is the reason you're here in this session you don't want to write code in six months later you're ready to go your eyes out so the content we're going to cover I'm gonna go through this real quick I had it up earlier it's right off the abstract or the synopsis always like to make sure you're in the right session so demo time I will uh I'll be happy to follow up with you on that I don't have any test code to test that with and dynamic parameters I actually rarely use dynamic parameters let me ask you how many people in the audience use dynamic parameters okay yeah if Mike if Robins at gmail.com I mean probably much family Mike huff Robin's anywhere I signed up for everything I can send up for like MySpace and all this sort of stuff I'll never use just so I get the brand so anytime he's still code from somebody just like this code I stole here give the person credit for it Thomas Rainer he's uh he said he stole it for somebody and couldn't remember who he stole it from so what that does I'm just throwing an error in case I run the entire script I used to use break but what I found break doesn't always break breaks designed to break out of a loop so I've had some scenarios where it didn't break and I started using start sleep so I would catch it in time and then I saw him present this and I decided to steal it so I think I've already zoomed into 125% I saw a tweet yesterday from Michael bender about people with that are colorblind set the the errors to uh to yellow so I'm gonna go ahead and do that I normally set them in the green anyway because we are gonna have some errors in this session and this is just prep for the session I've already imported this module I have a mr. toolkit module that's in my it might get her bleep robot story also just want to prove to you I'm not pulling your leg I did Windows updates today if I say hey you can bet you it's fact because I can't remember who I tell a story to so always tell the same story so I don't have to worry about remember what I said or it's at least what I believe at that point in time because what's correct changes just like with your code and so now we got yellow error messages we are going to skip a lot of this because I can tell that uh I'm gonna have a lot less time than I thought I was going to have we're going to send 1709 with PowerShell five one which ships in box with that version we've got powered power shell core 602 also installed let's jump back to the PowerPoint slide real quick I normally don't jump around but this is something new so I'll see how it goes so one thing I find people doing is uh they don't think before they write code they have no idea what they're trying to accomplish and they don't have a plan so they plan to fail so and learning is not equal searching the internet so what I would say that I search the internet all the time I download code all the time but what I do when I download it I want to know how it works and that's the reason I like script modules so much is yes you can put some dll's in there but generally the code i download doesn't have dll's because i don't want to bring black boxes into my corporation so if you're still in our borrowing code then just give the person credit for it and think about what problem are you trying to solve before you start and don't reinvent the wheel so has somebody else already rent the code you could contribute to maybe you could add functionality to and one thing I'll say what that is uh so if you go out to get hub and I'm a big believer I don't use like backticks for lying continuation but some people do they like their parameters lined up and if I'm contributing to somebody else's repository I'm gonna follow their guidelines but I'm not going to write my code that way when it's my code the worst thing you can do is go contribute to somebody's github repo and reformat all their code and say hey look I did this great thing for you every formatted your code the way I like it you know yeah that's not gonna get accepted so don't over complicate things keep it super simple and don't write code that's unnecessary a lot of people say well it's not hurting anything well it does add complexity so the thought process most of you guys in here should know a lot of what I'm going to cover in this talk talk for some reason as humans we have a problem doing the things we know we should do and I was talking to mark Manasseh about this last night and he's presenting right now by the way and it's his last presentation before he retires he recommended a book on this and I don't have the book to reference anyway avoid aliases and positional parameters and any code that you share even if it's a one-liner if - typically the rule is to avoid them in functions and and scripts if you open up the console you type out some code and you close it out and it's gone who cares what you typed in there now I say it's gone but it's always going to be there because of PS read lines so you can go find what you talked in but nobody curious about that readability and I've been there when I was writing my chapter in the PowerShell deep dives book jeff hicks told me I mean I had great code but it was all left justified and he's like put some spaces in and format your code and make it look better and I'm like it looks fine to me and say Jeff is that Jeff fix has been a good mentor to me he's left me some comments on my blog article that's really that's really helped me and I so I appreciate that don't write and I mentioned this already don't write unnecessary code I had somebody wants fun - Tom tell me like in the pipeline the the order you put your commands in didn't matter and that couldn't be further from the truth because if you select some properties from the pipeline and then you pipe it to where object those properties may not exist anymore and then just like pipe in the format table or format list you you don't want that in the middle of your command so order does matter one thing I would say with that and it's kind of unrelated to this but related to what I just said is don't put sort object and format table and your code unless you have to because it does slow your code way down because and it makes it where it's not reusable and we'll cover that more later so attention to detail goes a long way when writing code and power any kind of code and PowerShell is no exception one thing I'll say with I kind of have a problem with this that I'll write a function and I'll spend to the end of time on that function because I can always find something oh I could do this better and that better and something else so one thing I would caution you is don't do that you have to have a little bit of I don't care attitude and set of dates at a time that you're going to be done and Jeffrey's nobre he always says to ship is to choose so have a v1 and if you want to go back and add something then have it now to be a v2 feature and maybe you release it and you put that in a to-do section that hey I'm gonna do this before somebody comes out say oh well you didn't do this that and the other but set a deadline because you need code that works but you also want code that you can support later down the road so clarity and what I mean by that is uh is begin with the end in mind when you write something and know what you're trying to accomplish and once you know what you're trying to accomplish break it down and these are good lessons for life I found the general and I just apply on the PowerShell break what you're trying to accomplish down into manageable steps and then it seems like it's a lot a lot less difficult to figure it out and it's no different than this demo so it's in regions and it was a lot smaller than coming up with an hour and 45 minute session yes definitely I have problem you uh because me I know I'll get tunnel vision and I'll be focused on it exactly what I'm working on but I don't see the big picture so one thing with all this ultimately doing this stuff is about bringing value to your business and bringing money in the door and like me I work for healthcare company so I don't work I'm not selling anything and we're not a revenue generating department I'm sure I'm not the only one who's ever heard that so but the good thing is so and I have another slide so I won't go into that yet simplicity there's power and simplicity when you go down the road you know do you need pipeline support and do you need these different things because what I found these are when I write functions and when I had pipeline support it seems to double the amount of code that I'm writing and do I really need that now sure it's a nice to have so should you write a scrip or function I prefer to write something that's tool oriented and what I consider to be two oriented as functions and when I write functions so module autoloading was introduced in powershell version 3 so when i write a function i threw it into a module and i put it in the PS module path I don't have to worry about it from now on I just go open up PowerShell and call it and it just works I don't have to remember oh I saved that script over here over there over somewhere else it's also easier and I know that you can put scripts and the powershell gallery but i don't do that i ignore that because i disagree with that but you can have an internal nougat repository or the powershell gallery and it makes your code a lot easier to share so the other thing is what i don't do in my functions i don't put proprietary data and what i mean by that i don't put credentials aren't that server names i don't put so on because it makes it easier to open source and a lot of people have trouble getting their company to help them open source code but the company is really shooting herself in the foot because you will write better code if you share it publicly you're not going to write something that's quick and dirty and you'll also get peer reviews so if it's something generic that's not if like me since we're not a revenue-generating department I'm not giving the way anything that it's going to cost our company any money now then what I do I write Caller scripts and I put the proprietary data in the color scripts and I don't share those with anybody outside my company and those are real simple that they're generally real simple they can get more complicated but I just call the individual pieces the individual functions you also get ideas and suggestions when you share your code and you'll get contributions maybe you have a problem you don't know you have or maybe there's some functionality that somebody else needs and they may add the functionality that may benefit you and ultimately it's about writing better code you can get better code by by not doing anything you other than sharing your code okay so if you don't know what function is you might be at the wrong conference yeah so I know that's that may seem a little mean but uh that's why I have a smiley face there that hey if you don't know what a function is then we're we're you know we welcome you here and we'll teach you what it is so what's a function it's a list of commands or instructions that are packaged as one unit it performs a specific task so a PowerShell function should retrieve data process state or output data should do one of those things and not all those things so if you need it to do all those things you would write a function to do each one of those and then you would write a scrip and you would call those three functions and it makes sure just like I was talking about it makes your code more modular it makes it like LEGO pieces when I was a kid I loved to play with Lego and that's why PowerShell is a really good fit for me so the naming this should be a pretty much review for everyone here but just in case I'm not gonna make any assumptions Pascal case name which is like a proper case name capitalize the first letter of the verb all terms in the noun use an approved verb otherwise you're gonna get a warning when you import your module I'm gonna show you that here in just a second so use a singular noun and with a singular noun well that that's not nouns okay prefix the noun so I performed a technical edit on a book on a sequel book for a PowerShell and I was brought in late because the previous person that was doing that job quit it's one of the few technical edits I've ever got paid for because they wanted it done really quick one day into the project I was like yeah I'm gonna quit because uh the guy that was writing the book he had written a whole book without using verb - noun and his his deal was that he there would be collisions with other commands and I was like no that's not how you do it so I'm like you're you're not a PowerShell guy and the community won't hold you accountable but it'll make me look really bad and I'll be held accountable by the community so I said you know I'll just have to quit you can you can reform or I'll quit so I think the previous guy total nut and he actually did quit so he did reform and wrote it properly so sometimes on this stuff you have to stand your ground you know and don't do it do it the right way or don't do it at all so when you prefix your nail and so what I do you could write something like get version and if you wrote get version you're gonna get a collision somewhere and you could write get PS version 4 for getting the powershell version and you're probably going to get a collision there I would never prefix what PS because the PowerShell team may use that so you know as I was saying earlier my my initials are M are for Mike Robinson's mr. so you'll get get mister PS version or get mister version something like that so all my modules all my commands or Mis get mister set master and so on and I know hey there's other there's other people that I may get collisions but you can import the module with a prefix parameter and you can prefix those commands so that's pretty easy to avoid so an example a pre verb prefix singular noun okay jump back to the demo and several of these regions were just to remind me to go to the powerpoints okay so how do you think he'd create a new module if you search she you would think that uh with PowerShell that would be pretty simplistic and it would be new module write a new script module well you would you would be wrong because new module creates a dynamic module in memory and I'm gonna use it here simply just show you the warning so that's the warning there that you would see if you used unapproved verbs there's a list of verbs on the web I've got a link to it here but for the most up-to-date list run get verb from within PowerShell I'm gonna run it now one thing I will tell you let's just run get verb so when PowerShell core get verb or it turns a different type of object and it returns two new columns and it has a group parameter for just fielding filtering by group and on top of that there's two new verbs built-in deploy so the moral of the story here is if you want to make sure your code is compatible with PowerShell core and Windows PowerShell you have to test in both because there's things that work in PowerShell core that don't work in Windows PowerShell and vice-versa I've been running all my code in both just to see what didn't work and I've it found a lot because I don't use I generally don't use WMI unless I'm doing like DSC and DSC doesn't work in our show core currently so I've talked about part of this already let me just run these commands real quick so my demo won't fail so I talked about get getting collisions and get version get PS version [Music] and then I would run I would create it as get mr. version this is like simplest function you would ever write I try to keep my code simple when I do demos because a lot of times you can't see the forest for the trees when it gets really complicated so I'm just gonna query the function PS drive and you can see the functions on there they're not part of a module well there is one well there's one already loaded on there that's part of a module part of my mr. toolkit module and that's that mr. toolkits available and github in in the PowerShell gallery the latest code is on github so I'm gonna remove those and a lot of people that what they'll do is close out powershell and reopen it because it's not part of a module to get rid of those you can simply just delete them off the function PS drive and you'll notice that they're gone now the one that we had the an approver before still exists so with it anytime you have a module I mean this is this is pretty simple here but you would just remove the module which it sounds like it deletes it off disk or something but it does and I call it unload the module because it unloads it out of memory and then if we check for it you would see that it doesn't exist there's a lot of commands in here so I wasted a lot of time on my demos this year because I had the bright idea since I've been writing books on the lean pub I said I'll write all my sessions as a chapter in a book and give it to everybody well I guess about halfway into that project I figured out that there's no way I can finish this and get my damn eye ready to so I abandon that and I may do that at some point in the future you know but what I did is I took the book and I cut and paste out of it and then reformatted everything in here so if you read through this you're going to get the context of the book all except for this stuff updated this morning right before the demo and I did that also because Don told me not to do it so I guess I have to start covering up this might go and I say that sort of stuff so all the text says exactly what I've told you now dot sourcing functions so one thing I was told is you could go a long time and not understand the function PS Drive or dots or some functions and all that sort of stuff I'm sure all of us probably know what dot sourcing is but just in case you don't we're going to create a new function in a ps1 file and we're gonna add some code I don't like typing to be honest with you that's why I like tabbed expansion and I'll so I'm gonna inject code into my files so that I don't have to type and this is what one of the reasons I'm using I see steroids and I know other products do this too but I can just say yes and hey it refreshes so the problem when you run a scrip you could go a long time also without knowing this but I've ran the script I called the function in the script so we got an error it doesn't exist and then how many people know why I got this error okay good yeah see that's why I never assume anything because I've presented before and a lot of times people say oh well that was too easy and a lot of people say well that was really advanced so I have a hard time after working with PowerShell for a long time judging what I should be teaching because I'm like oh that's super easy and somebody else is like well that's really advanced so the problem is is the function is in the ps1 file and what it does by calling the scrip up here it loads it into the script scope so when the scrip exit it deletes the function so it no longer exists on the function PS drive it actually never put it on the function PS drive because all those are loaded in the global scope so what dot sourcing is and I could look at the function PS job and we would also get an error there but if I query the the well that does the same command I just rant if I dot source the function so there's a space between these dots and all that is it's a little confusing looking but it's a relative path so it's dot space and then the path to the ps1 file so if I run that and just to show you I want to make sure I didn't run these I put comments but I could I could not source the fully qualified path and there is a space in there or I could use the variable has the C demo in it so I could use a variable so that dot sources it and what dot sourcing does it loads it into the global scope so even when the scrip exits it still it loads it on the function PS drive and it still exists so now you can see sr-71 is the name of my computer and I keep saying I'm gonna rename it to the name of the guy in Star Wars the I forget his name fin whatever his like and see whatever name is there yeah too bad I don't have any more prizes so you'll notice it doesn't exist in a module now this is a great way to test your functions and what you want to do when you're testing your functions don't test them in the ISC or even vs code test them at the console and have you ever had the problem well it doesn't work on other machines but it works on my machine use the no profile option so when you call PowerShell dot exe or the powershell core executable which i can never remember the name of that thing there's a no profile option to make sure you're not using a profile that when you're writing functions you can always also use a require statement at the top and you can specify the powershell version that it requires and you can also specify the modules that are required because maybe you're using a module that doesn't exist on that target computer all that information is in here so we're going to go ahead and remove that function from the function PS drive we'll double check make sure it's gone it is gone so variables okay so don't don't use static values use variables and parameters Hungarian notation the fastest way to find out that if somebody knows powershell and i is to see how they if they're using Hungarian notation and I have seen people and I won't mention any names but on really important mailing lists who are experts in the industry but they're not PowerShell experts and they have email code wanting help with it with Hungarian notation because one of the problems we have in the industry is somebody there'll be a sequel expert or there'll be an Active Directory expert the sequel was a good example because they write code to and then they'll think just because they know transact sequel that they know PowerShell well we probably all know that's not the case because although I can write some basic transaxial it's probably not the best practices because I don't do it every day and even a so years ago I took a vbscript class and I took a window scripting host and I actually took a vb.net class and this has been like more than 10 years ago I've been at the same company over 12 years I still have some of my vb.net code running in production today that I wrote back then that is mission-critical so and I won't go into detail about it but I probably what I probably need to do the next time it breaks is I need to use PowerShell studio and I just need to rewrite a GUI on top of PowerShell to do that process because that's what I know a lot of sounds sequel I'll even suck the data out of sequel server and then do some some sort of translation or some sort of manipulation with the data and then I'll stick it back in sequel just cause I know how to do it PowerShell but I don't know how to do it in sequel ok that's Hungarian notation if you didn't know what it was it's typing your variables with string or int or so on and since PowerShell is a typed language you may you can uh you don't need to name it the type of object that it is if you want to know that of objects you just to get member you know it's really easy to find out the type of object so it should be out file and not STR outfall use a meaningful name for your variables that will make troubleshooting a lot easier so don't reuse variables and I'm guilty of this I have a good example a great example that I wrote some code and I used to variable and then later in the scrip I didn't need that variable anymore so I reused the name and it worked great and then six months later and let's see I have a slide on that I want to share now why it's okay it's the next slide why it's in context so anyway this is a response to me I was looking for help a great place to find help is on PowerShell Dow to work on the forums even as an MVP hey I don't know everything I ask for help and I believe in staying humbled but it's kind of funny that Dave white if you don't know who Dave yes he's a great guy he he's like he's like a Jedi like a PowerShell Jedi he's always got the answer and it's always the right answer if you've been on the parish show forum's I'm sure you've run into him but he tells me that hey I was using VM and he would use VM and VM objects instead of using VM twice because you can't tell what different type of thingies are in your variables so I thought that was kind of funny so a lot of what I'm covering in this session is pitfalls that I've had or things that's been difficult for me to learn sure exactly so you know six months later it seemed like a great idea on day one it worked perfect six months later I'm like who wrote this okay parameter naming so try to try to design your parameters like the building commandlets like computer name and it's computer and then a so C is an uppercase and the end is an uppercase try to and use the command let's that like ship with Windows even if Microsoft writes some and I'll pick on the azure command let's do not model your commands after the azure commandlets whatever you do and I probably don't have to say anything else about that you probably know it's exactly what I'm talking about so anything but the azure commandlets you'll probably be okay but the real built-in ones that ship with Windows that was written by the PowerShell team are probably a good example to model your parameters and your commandlets in general off of plural parameter names so a lot of people have trouble like I'm on a query multiple date potentially query multiple databases and should my parameter name be database or databases well there's documentation out there that says you should only use a plural name when it when it always it's plural value use that one except a single value which is probably never because if you can give it multiple values you could probably give it one so I never use plural names to me it's more standardized so avoid them so it if they if they can accept a single element then and I've already said this if they accept a single element they should be singular even if they can accept amoled moti elements so Pascal case name just like so this makes it real easy because you're gonna use Pascal case for a lot for your name of your command and for your parameter names don't use lower case computer name and what you want to try to do is when somebody downloads your code you want them to feel like that most people's gonna know how to use PowerShell if they're downloading your commands anyway or at least know how to call the commands and that way when they're using your commands and they're they've already used things like yet date and get service and get process and so on it kind of feels like the normal commands it's gonna prevent your phone from ringing if it's internal to your company or issues um github or so on that people can't figure out how to use it and help is another thing and we'll cover that in a second so let's jump into the present into the demo again we have about an hour left at this point so I'm not using the timer I don't need the timer yeah it's getting a little warm in here I didn't bring shorts one time I wore shorts I left a little bit Meridian Mississippi so I left home in shorts and I got to see out on us freezing to death and but I take the weather on Saturday it was colder at my house in Meridian Mississippi then it then it wasn't Seattle and Saturday we had some unusual weather it was 20 degrees difference in mine in my mother's house and she lives like two hours south of me okay so what I'm gonna do here I'm gonna do exactly what I just told you I'm actually gonna call the function right after I load it so I've used computer name and I've already to ask you why use computer name instead of server name host why should I didn't I've got the answer right there anyway so it really doesn't matter and it's about making your commands look and feel like the native ones and if in doubt just go query in the native ones maybe I'm unsure so I'll write a hey and why not use PowerShell to find out let's write a function so you should are you used computer computer name server name host machine or so on well there's a few which differ it differed uh different ones but by by large computer named winds there's a few with server name there's one with computer that's how I figure out how to what what command to use what parameter name to use it's so let's get back to our well there was one more command I do want to run so I had I had trouble with one recently and I changed the wrong one so I used file path instead of file but if you look at that 74 commands with a path parameter and eight with file path and that's out of the ones I have loaded because earlier I had no other modules loaded when I ran through my demo at the hotel and I had 32 commands or maybe 33 they had a computer name parameter and none of the other ones they had zeros so maybe it's that mr. toolkit module that I loaded that I wrote somebody tweeted out a really old blog article mine a while back I mean like from 2009 and I I've got a I'm gonna archive some blog articles because I tweeted back to them and I said whatever you do don't do it that way so of course I can tap expand to see what the parameters are but I prefer not to do that so I'll just show them in so right now I only have a computer name parameter because this is a function and not an advanced function there's another way to see them and get commands sovereign run it that way also so we're about to do something really complicated and when you don't know how to do this it sounds like it's like huge we're gonna create an advanced function really complicated it's so complicated that it takes one line to do it commandment binding that turns a function into an advanced function there's almost no reason to not turn all functions into advanced functions now you may have some helper functions and that's fine and what that gives you is common parameters so now I'm gonna run the same commands I ran before the only thing I've changed is add command lip binding so now notice I have common parameters and then you can see all the individual common parameters by querying it the other way most of these sections now have recommended reading so everything you ever wanted to know about power shells and help you really don't need to buy any books the about help topics are a great great place to read and what most books are they're just the cliff notes versions of the help topics ok so who likes to prevent resume generating events see as you can tell like I like to little live a little dangerous you know so do Windows updates before presentation update your demo say there's no what if or confirm for those things anyway we want to add what if and confirm support to our function and the way you add diet is supports should process that's it very simple and when would you add this that's what most people have trouble knowing when to do this they either always do it or they never do it so if your command is going to make changes then you would want to add what if and confirm if you're just running something that gets something that makes no changes there's no reason to add this so you can see now I've got what if and confirm and I'll just core it the other way and they're at the very bottom what it can confirm so if all the and see I said it again so luckily all you guys have a book already if all the commands in your function already support what if and confirm you have nothing more to do its automatic but if they don't then you have to write additional code I don't have a demo of that code but I'm going to tell you where to find the information so if you go out to my blog there's a free book on there it's called free book on Windows PowerShell advanced functions it was written by six MVPs and I wrote one chapter in it Jeff Hicks write the chapter on on a confirm and what if so you can go download that and read that chapter and it's a deep dive into that there's also parameter validation I read a chapter Jean blender wrote a chapter Adam Bertram friends white Savior they procs it was a entire week of articles and they're actually blog articles on our learned individual blogs but we can pal Jeff compiled it as a book and then I stole it and put it on my blog yeah I would definitely recommend going through there and reading that to get the details of that so now we're going to jump into parameter validation and while a lot of people don't consider this to be parameter validation I use tight constraints and I recommend it and what I mean by tight constraints is I'm gonna type computer name as a string so if I call it with one program with one value for the parameter it works fine if I call it with two again an error that's because I'm accepting one value because I've typed it as a string the problem with this you probably don't want people to ignore the computer name parameter but they can ignore it not give it a value at all it's probably not what you want so in order to prevent that you would use a mandatory parameter I'm not going to cover all the different parameter validations because there's like 50 million of them I could do it I could do all hour and 45 minutes on that so now what we've done we've we've said mandatory and this is PowerShell 3 + compliant code PowerShell two's deprecated so quit right in PowerShell 2 but if you wanted it compliant with PowerShell 2 you would say equal equal truth equal dollar sign true or equal dot you would you would never really have to say equal dollar sign fall she would just leave mental reality and I think that's one of the reasons they got rid of the equal true is because if you specify it its own and if you don't specify it it's off to show you how that works so now if I don't specify anything it prompts me says hey yeah gotta give it a computer name so I could say server a1 I hit enter all it did was return so every one it could have done did whatever so the problem is what if I want to give it more than one computer name so now what I've done is I've actually I'm going to allow it to have an array of strings still have the mandatory parameter now when I call it without the parameter notice it says computer name zero so I can give it motorboat it'll keep asking for names until I don't give it a value and press Enter so that's how you can restrict somebody to using a certain type like an integer or you can one day you versus multiple values so one of the pitfalls is default values do not work with mandatory parameters I see a lot of people try to make this work doesn't work so I've given it a default value here this here you call the function guess what didn't use the default value so what you have to use you have to use a different type of parameter validation if you want that functionality use validate not an old or empty so I've removed I've removed mandatory and added validate not an older empty there's a lot of these different ones I've got another good example too of one I never use you can do validate count validate pattern validate scrip I should have the about help topic in here that lists all those so now if I call it without specifying the parameter guess what gives me the local computer name because the default is environment computer name and it's preferably to use environment computer name of your daughter local host it makes it a little more dynamic it and it's considered to be a best practice sure yes what I would do is uh so you might be able to use yeah what you could do I wouldn't use validates it I would use validate script that's how I would do it and then that way I could call that other function and I want to show you Bella date script here in just a minute to populate that but dynamic parameters may be a better fit for that okay so when I do specify the parameter n values and I get the parameter and values so you get the best of both worlds and you also can't if you give it a null or you get an empty string along with the value you'll get an error because it doesn't well felt nulls or empties validate pattern I never use it you can write your own better so I've got this long regular expression of validate of filename who can read that who knows what that means anybody in this room yeah monastic salt this exactly right I talked to him last night and I'm like all this grouping and this look ahead and that gets confusing so the reason I don't use it I always like to be very specific there's a reason I do everything I do okay so somebody yes PowerShell will allow this the reason that so it tells you what you specified doesn't that match this pattern exactly probably nobody in this room would know what they're talking about either but you know definitely a normal user supply an argument that matches this yeah okay I don't know about you guys but I don't read regular expressions you can and that's what I'm gonna show you could do the help now I don't use the help in parameters because what I've done I've queried all the native ones and there's like almost they never use those so that tells me that normal users probably don't know to look for that help a simpler way is just to return a meaningful error message and that's when I write my own and use validate scrip I use the same regular expression very similar code the one thing that this allows me to do is return a meaningful error message which you can see here but at that point in time you're asking for your users input and I'm just using filename as an example probably you would have them put a path in and you would do like test paths on the existing file name okay yeah well typically what you want to do at least from a best practices standpoint you don't want to validate you don't want to validate input inside the function you don't want to allow it to get that far you want to validate input at the parameter and say nope I mean to me why allow your script to continue any further than it has to if if the user doesn't provide valid input and the other thing by using the parameter validation that's built in now is a custom script so it's really not a lot of difference in that scenario but one of the reasons I use parameter validation is my validation that our writes going to be very similar to anybody in this room so it's kind of standardized and certainly if somebody has a different way of doing things please speak up because there's been things that I do certain ways that I have changed based on knowledge from other people because I certainly can't think of everything I think I already ran that ok so now you get this message it's either not a valid file name or it's not recommended it's a you can read it and usually you're not going to write a lot of code in there anyway I'll scroll up just a hair so it's very simple it's just validate script it says hey if it matches this then true and if it doesn't then throw an error what up and what um what I'm curious and it relates to the other gentleman's question is something I have not tried is can I call that other helper function from this oh you can so that maybe the other option is just call your other script from here so that way your code is a helper function so enumerations are another way to validate to validate input so if I if I run this it's going to return all the colors so if I provide it with a couple of colors it's going to say hey yeah those are valid maybe I want to use pink sorry can to use pink so it's got to be a valid value inside the enumeration to be able to use it and the only thing of a I've done is is used it right here use the enumeration as a value or as parameter validation it's very similar to using a type constraint okay so how do you find enumerations this question I always get you can run this command here which is seems to be a really complicated one-liner it'll give you a list of all the enumerations an easier way is to warm frame we wrote a command called get type that you combine in the TechNet script repository I've actually added it to my mr. toolkit module it's still got warns name in it so you still gets credit but you can run that command and it returns all the enumerations so an example is the ones for the days of the week it's probably an easier way to get the ones for the days of the week so the other thing is type accelerators how much code have you seen people write to validate IP addresses and it may not be a lot of code but how complicated code have they written maybe a super complicated regular expression okay I'm the mouse so is this valid it is is this valid it's not and the good thing is for this little thing IP address that's it that's all the code are right and I can validate ipv4 and ipv6 addresses so hey ipv6 valid up ipv6 not valid now earlier I did some code and I imported my Esther toolkit module at this point and I got different output from that command and I'm like what but it's because I have the same function in that toolkit and it's different oh well that one would be not valid anyway I think it'll it allows strings yeah you can validate there's one for email addresses also yes so I'm gonna show how to how you how to get all these also say so I want to open up the one that I had earlier so this is what this was another one I wrote because the output I showed you is probably not the real really the output you want so I'll just go ahead and load this function so to be the last one loaded and it will win when I run it so now if I run this command that's more like the output you would want hey true-false true-false yeah so everybody always asks how do you find the tuff accelerators well with this command but there's an easier way I think it's called mail address yeah there it is that and it works really well I've tested it an easier way if you had the PowerShell community extensions which is written by PowerShell MVP by the name of Keith Hill and Keith works on BS code alight so he's contributed to that but you can run this command now what I will tell you is if you have the PowerShell community extensions installed if you have it previously run a command in there this won't trigger Auto loading is what I'm getting at so you have to import the module before you can actually run that command I kind of found that the hard way it's like why is this not working and it's kind of like PS drives they're not there automatically they don't auto load so we're down to about 40 minutes multiple parameter sets this is something I find that not a lot of people do sometimes I do it one way versus the other but and I'm going to base it off what David said is you should probably use the import them and use the fully qualified name because maybe have like the VMware module in the hyper-v module and maybe they have some of the same commands and you want to make sure you're loading the right one the reason that uh I loaded it a lot manually because I have my modules in my github folder instead of him that I'm developing instead of my PS module path so I import them because I would want to make sure I'm controlling when they're imported really and I could see that but yeah it's probably best just I would say to always be more declarative to be very specific that way you know you're going to get the results you expect to be explicit okay so we're going to create a function with multiple parameter sets and this is this is a little code snippet from one of my DSC functions so I've got a name parameter I got a module parameter and I'm pass parameter I won't name a module to be available in separate parameter sets so let's take a look at the syntax I've got two parameter sets if I call one I just haven't returned the name of the parameter set if I call the other one that works too the problem at least right now is positional binding does not work and I've actually told it what the default parameter said is so you can see the default parameter set is named not used to using the track track pad on this top have a docking station at work it's the other thing to be productive I like to have three monitors so and that's one of the reasons I use this is see steroids and I know other products do this but I break out the cuff the output pain on separate monitor and that's one of the reasons I still like this because you can't do that in vs Cade and it gives me more room to write Cade you know it's just a personal preference but I do use vs code so and while I'm talking about vs code ah I'll get back to the to this this is what my BS code environment looks like another video on configuring it this way it's on my blog oh we're not one more thing I don't think I ran this earlier but let's go ahead and run this and I know this font is really small but notice I actually have my BS code defaulting the powershell core so i run stuff in the IC and use windows powershell and I run it via vs code and I'll use partial core and if you're interested in that the it's all done in the configuration I noticed this morning I still had 6.01 referenced so when I opened it up I had an issue but I had to update that okay so what up the problem we we have is a positional binding is not working so what I found even though I set a default parameter name set I have to set a parameter in position zero for it to be positional so if I look at the syntax now you know you guys should know what this means in this room so I've got square brackets around name which means name is optional but the entire parameter is not optional because the entire thing is not in square brackets and module of course you can't have module name both positional because it wouldn't know which one but if you use module you have to specify module so now notice I'm going to call the command with without the name parameter and it's going to work positionally there's a little bit bigger problem that I found or some it's a little misconception let's do this so I want you to notice here so what I've specified I've seen a lot of people do this it's a specified parameter set name then module and I specified parameter again with all the different options that I want to be the same in both of those and this might it may initially appear to work but it doesn't work properly that's because you well oh I'll get to why it doesn't work if I can select this there we go so notice path is in position one now so I can pipe something in I can pipe in the path hey it works great I can look at help for that parameter hey I can pipe in by value and buy a property name that's that must be a win the problem is and then both the parameter sets for path it actually shows value from pipeline and by a property name is false when you drill down into it so how's that what's the deal it's because I didn't read the instructions I didn't read the help topic so if you're going to specify all the same options and both your parameter sets for the path parameter there's no reason to specify parameter more than one time just say parameter and specify which you want and say that's it it'll be available in both with all the options so the only one I'm gonna skip these first two and then run this last one because the first T is gonna return the same thing as before so what I want you to notice is now they're available by a property name and by by value I hate the word by value to me it's by type it should be by typing by property name because by value actually binds by type so what if I want different options for path so what you should do is be explicit and notice the square brackets opens here and it closes here and that's for name and then I'm explicit again for module so I have to specify the options that I want in each one of these blocks for that parameter net name and it works perfect it's one of those things when you search the internet on how to do something instead of figuring it out for yourself let's do this make our life easy can get the close one and we'll just run the last one so specify different options that's what I'm trying to show you here so you'll notice with one of the parameter sets its it can come in by value and by property name I thought I had different ones maybe not I do okay thank you but I ran the entire thing one more time after this I have a couple things I definitely want to cover it's not very intuitive there we are okay so the bottom line is false one of the options you got tree falls and you got true tree so that's how you get it different options and it works perfectly because until you drill down into these commands you can't see that there's a problem I think we're going to come back to well let's see we've got about 30 minutes I'm gonna come back to the return keyword because that's totally separate but I'll just cover it real briefly is return is probably the most overused command in PowerShell and it can cause you a lot of pain too because when used inappropriately it will actually exit out of a loop and not return all the values that would normally be returned now when you're using classes you need return you have to use returning classes I do want to show you this real quick I can't leave you hanging in some PowerShell for a routine new mr. Guidi function because with DSC there was no new new grid command so how you turn so hey it looks great so what's the big deal you can get the same results by just calling the variable that's not really how I like to do it though how I like to write my commands is to use write output it's gonna be the same output the problem is it's not always the same and there's there's really no reason to store it in a variable and call the variable any way you could just output the value cut to the chase so this one I'm not using return so without the return keyword it returns any greater number then 4 is returned so notice that 5 7 9 same code I'm going to add return who knows what's going to happen there you go so you guys know this so that's why you if you're in the habit of using return and you use to return all the time you're going to shoot yourself in the foot so and I'll just show you that real quick it's going to make sure we so it's going to return five and then that's it at exit exits the loop now I've kind of got the same sort of thing going on here this shouldn't take very long so we just use a range operator and give it one day ten and notice the total seven items were returned so we add return I have a detailed blog article in this as well so now when I run it with return guess what we don't get the Burgos outfit first value that's it you should use it in classes and if you understand how to use it then yes because you may want the functionality I just showed you you may want to grab the first value and then that's it just to understand how it works and the the help topic for a return is really good I've got a like well I believe I have a link in here so what if I run this oh yes I've got all the all the links I have in here go to the powershell core help topics and I cut the version off the end of it because that way it'll go to the latest version even if you look at this in a couple of years and it they've got urgent 14 now sober brace output you guys probably know how to do this but I've got inline comments so if you're doing something like return you might want in inline comments but nobody's ever going to see this and well from what I found people will go update the code and they'll never update those comments so I would rather have no comments and comments that are wrong so when I run that with the verbose parameter sorry can't see it same command except I've used a right verbose you call it without verbose you don't get it you call it with verbose you get it so that's it for a right for bass pipeline input though what fine so we're we've got about 25 minutes okay so what we're doing here what we've added we've we've made a parameter mandatory and we're accepting pipeline input by by type they call it by value but it's really by type it's going to but if I pipe a string into this it's going to bind to the string and that's why you can't have value from pipeline on two different strings and if I pipe these to get member of course if I scrolled up you guys know that those are strings server one and server two it's pretty self-explanatory that's what I'm going to do now is create a custom object it's got a name of computer name and it would show PS custom object if I piped it to get member when you pipe it in some older versions of PowerShell would actually give you an error but newer versions just give you some output that you don't want so now let's try by property name one thing that well and I have another script to run so now I'm gonna try to pipe my strings in and guess what nope we don't accept pipeline input by type but if I pipe the custom objects in they work just fine and also be aware that syntax I was using this version three well actually the mandatory would be equal true if it's version two but the value from pipeline I don't remember if they had true on it or not but anyway I quit right in version two since it's deprecated I do have one box with version two on it all my all the boxes in my environment have five one it says for the exchange server don't touch it it's written exchange 2010 but we're in the process of uh it's in hybrid mode we're going to office 365 so what I have done here and see there it is again somebody wins a book I've allow value by a pipeline by tight and by property name so I can pipe in my strings I can pipe in my custom object and hey it works either way but one thing to note with this is it's always going to try by value or by tight as I call it first it'll only try to bind by property name if by type doesn't work I think Don in his book he called it plan a and Plan B so one thing that trips a lot of people up is the values you pipe in are not available in the begin block so notice it should say test and output the computer name it's only going to say test because you can't access those values in the begin block so let's get cover error handling real quick I think Jefferson over covered this a little bit yesterday there's something very specific I want to cover so I have a function it has no error handling I try to query a computer name that doesn't exist and I get an error message it's an unhandled exception so the only thing I'm going to do to this truck hitch is what you add for air handling so notice when I'm : test WS man I have it inside the try block a catch block so with track hitch a lot of people think oh I have to have a trial block have to have catch block that's actually not true you have to have a trial block and you do have to have a catch block or a finally block but you can't have all three but to me always have a catch block I guess the one that's why people make that assumption but guess what it's not going to work so still getting an unhandled exception and why do I get an unhandled exception because it's not a terminating your so I've said I've added erection stop to this so one of the common questions is what I do if I'm running a Dulles command or something in dotnet it doesn't have erection parameter on it so there's a erection preference parable in what you can do is immediately we're out immediately before you call the command change the erection preference and then call the command and then change it back but what you need to do is actually still with air action preference parable value and another variable because the default is continue but something else could have changed it from continued to something else so you want to make sure you get it back to what it was originally after your command runs so don't make assumptions really so the comment is that's a good place to set it back in the finally block and I've never thought about that but that is a good idea I don't know why David didn't that raise his hand when a I asked for power show expert or maybe you did not it notice I mean this is actually free so you guys know he actually he's the guy that writes the code he wrote PowerShell studio so now when I call it I'll get a so I gave a warning instead of an error so much nicer so we've gone a little over 15 minutes left my alarms about to go off so nobody panic it's not a fire alarm comment based help I've got long leave comment comment based help and comment based help is dead because I've been looking at mammal but I talked to some other MVPs I was at the NPP summit last month here in in a Seattle and although platypus is available when there's a session this week you should check out I'm not sold on a mammal based help especially after what I heard yesterday and what most MVP said for the code they're writing what I've been told in the past I still hold this as valid is if I'm gonna write something to sell I'm probably going to create mammal based help what man will be self gives you is multiple cultures so different languages help for different languages and updatable help that's the two things that buys you the most MVPs that I talked to they said what the code are right if I need to update my help I'll just publish another version of my module a minor version and the other thing is uh they said I wouldn't attempt to write it and different cultures you know especially the people like like me I only speak one language so I don't think I'd rescue Google Translate there you go okay so I'm gonna skip over those sections so a script module how do you create a script module if you rent help new module you would find out as I previously said that creates that creates dynamic modules in memory there's no command for creating a module it's called new item so I'm gonna create a folder and a file a ps1 files to your script module is resides in a PS m1 file I'm gonna inject a couple of simple functions into that file and open it up let's close these out I was glad to see yesterday they mentioned there's a command similar to PS edit in PS Kade that's one of the thing pieces of the puzzle I was missing so I try to call the command hey it doesn't exist what's the deal so yeah so that's the arm to let me know that John Don Jones is gonna show up in five minutes I did not so anyway you see where it resides that it's not in the PS module path that's the problem so I would had to import it explicitly or put it somewhere in the PS module path so the PS module path and let's see got a few minutes so it's pretty easy to get the PS module path you guys probably already know this I had a WS commandlets loaded so I have one extra value here I want to talk about these real quick because these can be confusing just clear the screen before we yeah do this okay so the first one I never use this why because that's not my My Documents I have three active directory users one I'm a standard user on my desktop I'm a standard user in the domain number two I'm an admin user on my desktop standard user in the domain and number three I'm an admin on my desktop and that admin in the domain so I login as a standard user and then I run PowerShell as an admin so it's a different user so Mike F Robbins is not the user I'm logged into the box as so if I go to My Documents it's not there now that's one thing change I've made what vs code I run vs code is a standard user and then I actually if I need to test as an admin really you only need to run PowerShell as an admin if you're doing something that requires UAC elevation on the local box if you're running stuff against the remote box UAC doesn't come into play anyway so the second path this was ad in PowerShell for this is where you should put this is the all users path and typically what I would recommend is put all your mop production modules in here that our user created and this is where the PS gallery installs by default unless you give it scope of user say that again yes and that I guess that is one reason to run this as an admin because you would go and see the problem with that I have another problem because the user I'm logged into Windows doesn't have access to that users yeah so it's it's kind of a chicken and the egg problem it's okay yeah it's not something I do or I've really thought about you would it would just be a dependency that you would have to validate that would be my main concern is having a dependency that's not there by default but it's no different than they WS module you know so I wouldn't say it's a bad thing if it's a standard in your company I believe in consistency so if that's your standard set it as a standard and stick with it so the the Windows folder the system32 you'll read some of the outdated documentation that tells you to put modules in here that is false I've been told by a member of the PowerShell team are multiple members of the parish whole team you should never put anything here unless you're Microsoft now I think the old documentation was before this all users path existed and I'm curious to know you can install the powershell gallery on powershell 3n 4 and i'm curious to know if you install the powershell get module on powershell 3 how does it handle to all users or does it create this because that didn't exist in PowerShell 3 the one thing that can trip you up on this is the PS Auto loading preference which has no value by default I changed this once upon a time to nine because I wanted to go back to the functionality in version 2 well yeah it doesn't work that way if you set it to none it means none no core modules no nothing you have to import everything so if you run into trouble with auto auto loading and you know your modules in the right place you might want to double-check this and if you're if you're like David and you want to always module qualify you could you could set it today yep okay module manifest we need to move this trackpad is killing me okay so we moved it in a PS module path didn't do anything else no importing no nothing just copied it guess what now it works so I do like that functionality but you may not get what you think you're getting there's an order of precedence to you with a aliases and functions and commandlets I know that Geoffrey Stover I think he he talked about that in his unplug demo at ignite last year and that was really interesting so if you if you run get module when you see a module at 0.0 it's a dead giveaway that that module probably does not have a manifest because I don't know of anybody who would publish a module what 0.0 I heard it one time from Lee Holmes who said all modules should always have manifest and it's metadata about your module so we're going to create a new manifestation because it's a really long line I don't want to use the back tickers line continuation it's not exactly I don't think that's what splatting was designed for but it works well is that I think it was designed so you could dynamically allocate your parameters like if you have a credential parameter you can add it to a you can add it to a hash table if it's specified but not if it's not specified you can check the PS bound parameters so I've got a little snippet here about lying continuation and I think I'm going to skip that because I think I've talked about that enough there's a plasterer session this week I'm gonna cover plaster real quick this is kind of getting toward the end of the demo so you're gonna start from the Parrish show gallery I have a detailed blog article that I wrote recently about this a lot of my recent blog articles were building up to this session I was like I don't have time to blog in and work on this session so what I've done here I've actually created I've created the information that's required for a plaster template you know I've stored it in hash tables and I'm gonna splat that also I open up the XML file that I just created so that's what it looks like it's got my metadata basically in it and that's metadata about the plaster template not about the modules I'm going to create a ps1 file that's gonna be used for every one that's my script modules it's going to dot source the ps1 files when I open that up so I use something like this on every one of my script modules because I put my functions in ps1 files who want to put it on github it's really easy for somebody to grab one function there is a link in this slide deck from from a VP from Europe to us all do something last week that I'm really interested in I like this for github and for development but I would prefer my functions to be all in the ps1 file when I put them on the power power shell gallery for production he's written some code to put it all back together and do unit tests and all that sort of stuff on that so the plaster does that okay I did not know that I'm actually a newbie with plaster what I did I used to have a function that created my script modules and functions and it was very specific to me and what I decided to do was translate that exact functionality to plaster to reduce the learning curve so what I'm going to do now is actually update the plaster template with the information that I I want to add to all my modules and it's not that one this one so you can see here and there all my modules I've got parameters here and I've provided some default values it's gonna want the module author's name and all that sort of stuff and then it's gonna prompt me well no it's not gonna prime it's gonna replace this with some of that parameter information excuse me keep forgetting about the microphone one more time so what I'm going to do now is create create a script module so I have to give it this information so I'm giving it all the pass now what I would recommend when you create your script modules the only thing that's required I believe is the path but from what up found if you don't give it a route module your module won't do anything now found I've actually seen some with DSC that doesn't require a route module and I have it figured that out yet why it works but for the most part you always have to have a route module the other thing I would recommend specifying is the description and the the author because if you're gonna put it in PowerShell gallery those are required actually if you're gonna put it in a nougat repository the PowerShell yet those are required because they they run test module manifest against those and we didn't run this yet but we ran this okay so and I use the various parameter if you have any problems that can give you additional information so you'll see where it's located at now it's my demo folder that's my plaster template there I should have had that moved up in my demo a little bit because I just created the module okay there's a session on PPS script analyzer this week so if we got just a minute to cover the format data that's the last thing on the list of what I said I would do that I have it done so notice the last thing on this this is pretty standard function but free space is the very last thing I have to add this to my functions to export so I wrote a pester test I can actually test it and see if it exists and it does update the module manifest to add the XML file make sure that they still exist sorry import the function let's call the the function before we re imported maybe I have to report it thought I had already imported it once what I want you to notice is so this is in the list I don't really want to list so we all know that hey if it's for properties or less it's in a table and if it's if it's more than four properties it's in a list so what I've done here I've added one line to this very bottom line I've added this type information instead of being a PS custom object it's going to be a mr. system info I need an XML file that's going to specify the ones that are going to be listed in the table we'll get there I actually have to update the module manifest to tell about the format's to process file re import the module and when I run it this time I'll get it I'll get a table now the other thing you're gonna you can do and the code is here if you want to see it let's so we've got like one minute one last thing you can always do one more thing it's like you tell your wife you know or your husband just 5 more minutes and you're like dr. Jekyll mr. Hyde you know on the computer so now what we're going to do we're actually going to add a tight file because I don't want my output in bytes and all that sort of stuff we can run all day so we'll add the tape file to the module manifest we import the module again we'll run the command guess what now we've got it usable values but the thing that this buys you is those original byte there you still exist in case you want to use them down the road so if I say yeah I know so notice I've got size and longer values and that's the last thing I want to show there I'm going to jump back to the slide deck real quick and I really want the last slide well we need this slide we can't leave without seeing Jason again so when you get through and you've written great code then six months later you'll be the guy drinking margaritas instead of trying to gouge your eyes out so I've got some resources in the slide deck and that's the last slide those are all the books I've participated in this is the one that all you guys got a copy of if you want my email address go out to my about page and decode it it's encoded thank you [Applause] you
Info
Channel: PowerShell.org
Views: 25,498
Rating: 4.8095236 out of 5
Keywords: powershell, windows powershell, techsession, powershell summit
Id: d5x0Di52QZA
Channel Id: undefined
Length: 104min 44sec (6284 seconds)
Published: Thu May 03 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.