Building a GUI with PowerShell - Donna Ryan (@TheNotoriousDRR)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
i'm just waiting for the stream to catch up hi everyone uh you're not gonna believe what's happened but we just started the stream offline and i didn't actually hit go live in youtube i feel like such a plumb so let me start again i'm so sorry donna it's okay let me do the quick spill again thanks everyone for joining my name's adam cook this is powershell so hampton this is donna ryan here with us today um excellent people are now coming up in the chats and here we go so this is good we're actually making a real start now awesome um indicate the length so it's gonna be about an hour give or take if you need to drop off that's okay you will be able to catch the recording afterwards uh it should be available for you tomorrow morning on the youtube channel um the chat there is a chat functionality some of you are using it already but in case you're not familiar please use it it's on the right um it's live engage with us ask questions we will be very engaging we will respond with with any questions you have done is okay with with me because you don't have an opportunity to come out on microphone donors don is okay with with me just interrupting her with any questions you have so please ask them when they come up ask them and we'll engage um and there's a quality setting in youtube video in case you're not already familiar if you hover over the video and you click the settings cog and go to quality and you'll be able to choose 1080p and i recommend it because when we get to things like screen sharing looking at code that will help you tremendously and if you experience any buffering perhaps your bandwidth may be an issue and you may need to drop the quality but youtube might do that automatically and then one last thing donna before we hand over for the second time i just want to say um thank you to the powershell community because without the community i wouldn't be able to do the streaming the way i am now so to everyone in the powershell community thank you very much and here we go the second time please all right so hi folks i'm donna ryan uh and the topic of today's presentation is going to be building a basic gui with powershell it's a topic it's a little near and dear to my heart as i've written a little community tool that's gooey driven um so just a little bit about me here um professionally i am principal consulting engineer with cdw it's a little company um it's not it's ginormous but um i'm out in the field mostly doing systems management work i've been with them since nine years nine years this month actually i earned my enterprise mobility mvp this year uh so yeah that was kind of cool i'm a blogger and a contributor at msendpointmgr.com if you're familiar with you know the driver automation tool or you know the osd front end um some of the intune tools have been coming out that's mostly where my contributions end up i've gotten which lives over there as well uh i'm the lone developer win which so for those that aren't systems management folks that are here just for the powershell wim which is a community tool that i started writing last year uh which has caught on in popularity and is being used all over the world um i'm pretty proud of that one as well uh but the the big takeaway of this whole presentation isn't so much of you know how to build the gui it's you can learn how to do this too and you can get good at it to put this all into perspective um i've been using powershell for years in the i need a simple function to do just this i think the longest script i had written up until july of last year was about 40 lines and in all honesty i didn't know what a function was what tri-catch was uh how to build an array i i didn't know much anything i just knew that i wanted to build this tool so that you know if i can do it you guys can do it and that's really what i'm you know hopefully the takeaway that you guys can leave with here is um some motivation or some confidence that you know if a dingbat like me can pull it off and make a successful community tool uh you can do it as well and you know also as a shout out to the community as well um i relied heavily on the community and the bloggers uh for things like how to use get dash item all the way to uh how to build the gui and everything in between pretty much everything i wrote in wim which which is now about 7 000 lines of code i more or less had to google at some point to figure out actually how it worked so um again you guys can do this so then the software that we're going to be using to to make our gui we're going to need ise and you know while i've used vs code i still use powershell ise because i'm a creature of habit i've gotten used to its its quirks and its crashes and i know i should move over to vs code it's clearly superior but it's forced to have it we're going to be using visual studio i like using community edition because it's free um for the amount that we'll be using visual studio make goobies we're barely scratching the surface of its functionality but for what we need to do it's a fantastic free tool and then the last component that we're going to need is a parsing script and we'll kind of delve into what that does a little bit just trust me on that i have a url here that you can use to grab the one that i did if you want to screenshot this or take a picture of it cool i'll have another link to the master blog where this came from but we'll use that to actually convert the xaml code into um something powershell will accept and will allow us to to interact with and just for a moment of credit um there's a guy in the community stephen owen i think he now works for microsoft has a blog called foxdeploy.com he has an absolutely brilliant series called learning gui tool making and that's what i learned from i only made it through about step part three and a half out of five because i just try to start dorking with the code and making it into you know running star trek jokes um there's a lot of star trek jokes hidden in wim witch so it's kind of one of my things but um if you want to afterwards get more in depth want to know some more of the whys in the house or if you like following around and written i highly recommend you follow his series it is fantastic it is probably the best if not one of the best out there and how to do what i'm doing um i can't say enough good things uh and if you want to if you're on twitter which you should be on twitter um go ahead and give steven a follow um a great dude and his series is fantastic so let's talk about this method that we're doing um there's a traditional method which is uh the forms method which you go through in powershell and you type out every object so you want to draw your form you have to declare your form and how big it is and you have to declare all these things and know the coordinates yeah that's hard xaml the xaml method is easy and that's why i'm using it so what we're going to do we're going to go into visual studio and we're going to draw our window and we're going to put our buttons in whatever we want into in there and then once that's done we're happy with it we're going to copy the code out and we're going to paste it in the parsing function and at that point we can start actually working with it in powershell it's pretty it's pretty easy it's the objects that i'm going to start with are some of those basic ui elements you check boxes because that's going to give us boolean options you know if users check this then you can do this option if this box isn't checked then do that buttons the way users can initiate actions text boxes for users to input data under those some of these have unique properties that we're going to use check boxes is checked which tells us if the checkbox is checked or not the button has an ad click which tells the ui that the button has been pressed and then to do something and then with text box the text property actually contains the text i'll show you where all of that stuff lives but there's also a common property we're going to use called dot is enabled and that allows us to make objects interactable so if you're familiar with the idea of having like a something grayed out in the ui that's dot is enabled and i use that extensively in win which i'll show you how that works as well so awesome enough of powerpoint for right now it's enough slide decks so let's go ahead and oh where do we want to start let's go ahead and start with uh there's stephen's blog here fox deploy you can find the script into you know right here if you want to go ahead and grab that's where it exists let's go ahead and start with visual studio because that's going to be our first step so when you're starting to work with this you're going to going through and making a a new and i'm going to do add a new item this wizard can be confusing because there's so many options but the trick here is you want to select wpf and this also applies when you're building a new project from scratch i'm going to go ahead and give it a name down here as you can see i've zoomed in and i'm spelled world but that's fine and we're wpf and so what visual studio is going to do is give us a blank canvas now the way that this thing works and this is actually pretty cool is this is what our user is going to see and interact with this lower pane actually generates the code now you can also mess around with the ui directly from the code so let's say i wanted to shrink that window down a bit i could go ahead and that's what i did here is i just went down into the xaml and i modified the width property and it runs live the really the benefit to this is when you if you start getting it really in depth sometimes the ui gets really fiddly with grids and where tables get lined out so sometimes it's just easier to go down into the code but the takeaway here is you can you can mess with either there's a little toolbox over on the side where we can have common objects so you know as an example here and you got buttons check boxes combo boxes there's stuff in here i've never even used i don't know what a grid splitter is i probably should i don't know what an expander is but um for the sake of we're going to go ahead and just start with some basic objects so we're going to take a button oh and let's take a checkbox there's a happy little checkbox and where is uh text box text box and text block uh the difference between those two just for those that are curious text box is interactable where you can actually type something a text block just gives you essentially a blob of text that you can use to label things um it took me a little while to figure out that distinction so i'm going to take a text box and we can see we once we dump these in here the code has started to populate and you know it knows what these things are because there's a button a check box and a text box and we also see that there's various other properties that are in here there's heights and alignment and all that kind of fun stuff but if we want to make these interactable within powershell we need to do a couple of other things here one we need to give them a name no you don't if you want to plunk an object down in here like a text a text block and you're not going to use it as part of equation you don't have to name it but for things that you're going to interact with or pull values out of or make it as a part of the process you need to name it and so how does that work great question let's start with our text box on the right hand side you'll want to pull up the solution or the uh the properties and if we look down here it'll default to the solution explorer tab don't don't bother with that properties is where the money is and these properties that exist all through here the is enabled um the text the visibility those are all properties you can call from powershell and what's neat is once you've named this and powershell registers is an object you can modify those properties from your code which is how the whole how the magic happens so what we're going to do here in order to make this usable we need to give this thing a name so i would call this now why why i was running to this last night why won't you let me rename you all right boy the demo gods are not smelling on me today are they they are not let's see can i do that will that change it boy that's embarrassing i don't know why i can't modify it okay well tell you what moving on because we are you doing live demos i already have something else pulled up where i made the modifications so we can move forward now where did my property windows go oh boy that's just slightly embarrassing isn't it all right you just tried closing and reopening it yeah i'll try that let's see let's see if that'll take don't save any of that at all let's try that one more time if not i can still i can adapt persevere and overcome the old-fashioned american way yeah that's how you get through live demos because inevitably something's gonna go south all right so we click on check box oh if i do view can i do property window okay there's properties all right there it goes now can i change this name hot damn okay i can't so all right yeah there's must have been some sticky setting or something so anyway let's pretend that we had that old window and we went ahead well actually i could just show you how this works let's go through another button on there their button has no name we can go here and we call it button2 don't need that but that's how if you want to make that interactable and use that as a as an object you need to give it a name full stop that's that's critical everything else is somewhat optional so let's say we've got our we've got our form here and we're happy with it we're ready to roll with it what we're going to do is go into the lower pane we're going to do a control a and a control c and we're going to move over to powershell actually what i want to do here as well is because i don't want to i actually reuse this template fairly often i'm just going to give me a give myself a scratch one and what we're going to do steven was kind enough to include instructions and this is what makes it so awesome is that note your example goes here it's absolutely true so watch watch this witchcraft we're going to go in here we're going to copy our text we're going to go back over to here we're going to clear that out and paste it in and we can run that now where's the ui well it technically hasn't been told to load we haven't really modified this really for production use yet but the takeaway here is a couple of things the script um as it's as it's written if you leave the defaults you have those names that we supplied what it does is actually goes ahead and tacks on a wpf and why would you want to do that so you know um if the variables you're interacting with are a dub or a wpf object or if it's another or if it's just some other data um object so it's kind of nice to know that you're interacting with your form versus interacting with a data set uh the other thing this is your command to actually show the ui and what you can do in the script is you can just have this line there right at the end and it'll auto pop up so what we're going to do is we're going to take that little line of code there and we're just going to go ahead and run this and then assuming ise doesn't crash i gotta love ise let's try that one more time come on run and then hold it remember that i typed that in nope all right so there's our ui just like we had before so that's really how it all works is you just paste it in and you're not something you can interact with so i'm going to ignore that one and we're going to go right to the demo which is more or less the same thing i made a couple of minor tweaks just before you start that we've got one question here actually it's um the definition of wpf windows presentation format format and that's like a syntax thing i guess like what's that in definition do you know i don't know i think it's like a method right of doing gooeys at least i think so i really i don't know what the the hard definition of but it makes it easier so that's that's that's the takeaway it's much easier writing the code by hand okay um so what i did here if we want to look at this code uh actually i've got that pulled up in visual studio here is i set a property and i was monkeying around in here but this is a property that i had set i set this is enabled and i set that to unchecked and if we look in the in this part you really can't interact with it well you shouldn't be able to interact with it and we see it's grayed out and but what's cool too is we can see that in our xaml i passed that property and the reason why i did that uh is to show how the checkbox actually works so here we go let's go ahead and look at our text output sorry sorry to keep jumping around here so what we can do we've got a check box and a text box and a button let's see what this thing does so i'm going to hit the button and if you notice what it's cl outputting to the console is to enable the checkbox okay i'm gonna go follow instructions what if i don't want to well i can't type into it okay let's turn on the check box hey look at that that's now not grayed out so now i can type in now what happens and now it's actually taking the text that i've put in the text box and outputting at the console so how does the actual code work and how are we leveraging that to make this functionality work it's not that bad parsing script stuff she let me do well you know that's fine i'm going to close that blank m is not working oh well so into this script all of everything from above this point is all loading the ui this is this is my code here so let's look at the checkbox functionality and kind of take a dig into this a bit so what i've done is i've declared that if i click by using this dot add click because remember i actually named this check box in visual studio i named it check box and then the parsing script packed on the wpf which is how i got the name and then what i'm doing is i'm using the dot add click property to tell the ui that if you click on this object um register this action and everything that you put in between the parentheses it's going to do so you can put in if statements like i did you can have a call a function you could have it run another script you could ever run an executable you could have it change your color whatever you wanted to do you click on it it's going to work now typically though what you're doing with the checkbox is you're doing some type of boolean action so what this is doing oops zoom back in and then click so what we're saying is if you click on the check box run this if statement and the if statement says if the check box and its property is checked is true uh use the isn't you know change the property of text box to true if the check box is uh or else uh essentially disable the text box so that's is enabled equals false that's what we're doing is when we go ahead and click on the check box it then runs this little if statement and then determines if there's a check if the check box is ticked enable the text box if it's not ticked disable the check box and from those type of boolean those boolean function you know that that and or you can derive a lot of power from a ui you know do you want to load this option check user has agreed to this eula click the check box now you got the next button comes up so you can do a lot with just as little code snippet it's very very powerful and i use it all the time from the button it works in more or less the same the same general idea you have this ad click which is telling this the console again that you've interacted with and you clicked on the button but the button doesn't really have much of a property like a it is checked which is fine it's just the nature of the button so what we're going to do is when we actually use that click uh it's going to do whatever it you know ah crap i'm still trying to get the hang of zoom it that's handy but it's a little fiddly um but same same principle everything inside the parentheses is going to run typically what i'll use in win which is you know i'll have a button and then i'll have the button call a function and then it does something and it returns an action and cascades but you could have it do whatever you needed to in this case we're just doing right host so in this case what the button's doing is our little code snippet here is saying if the checkbox isn't checked enable the checkbox and if it is checked oops crap write the content of the text box and this dot text is where what's written inside the text box actually resides um and i use that one quite frank frequently in wim witch as well because i'm asking where mount paths are file names um oh image names image versions and a lot of that's all stored in various variables.txt because it's all displayed to the screen so that makes it a really easy way to get that data out and then manipulate it and then how all of that and that's really all this is doing is just calling a basic right host function and so there's mostly not much more to it it's pretty darn pretty simple um any questions on the check boxes the buttons the text boxes i've got some more complicated stuff but at this point if there's any questions please feel free to shoot them at me so far we're good nothing nothing just yet but when they do i'll definitely pipe up okay uh so let me kick back to the slide deck for one more relevant page uh slide show from current slide uh i'm glad i learned where that button is oh i've got one that's just come to mind i was going to ask i'm sorry sorry destruction flow there not a problem um so when you execute say a function you said in wim which are you you know you invoke a button it does some function goes away and does something what do you what do you give the user in that interim period like what can you give the user like a what's their experience does it look like it's hung and not responding sort of state or can you present like a little swirly thing uh well i've been lucky for the most part and win which when you're interacting with the ui it's pretty responsive until you hit the make it so button and that actually triggers the whole build process at that point ui more or less just locks up i know that there's ways of doing parallel processing um i know that there's you know some community tools out there there's like my apps or my apps that lights up because it's invoked dism presumably and it's waiting for that return is that right right yeah it's all it processes everything in serial so that's been one of my things i needed to learn how to how to to make it more usable so while it's running you can do other actions i just haven't gotten there yet so um but you know for smaller stuff really doesn't make a difference like if you're trying to have the form to onboard a new user in 80. do you need to have parallel processing probably not so if you're going to download a 4 gig payload you may want to just pick that battle sure cool anything else chat room um i haven't put anybody to sleep yet have i uh there was one sort of question from jason gibson so you could say use is enabled to have the check box disable it or enable the button like a user i think that's a question but yeah you absolutely could sure you can also use the button to close the form too i've got i can show you a little site a little script i wrote a client later just to do one from soup to nuts it was designed to run in windows pe in a task sequence environment but that wasn't know that what that line of gibberish means uh slideshow let me go back to my one from my current site okay so there's two other very useful form objects that i use very very much and are very helpful and very useful there's the combo box and the list box the difference being the combo box if you're not familiar with that term it's a drop down and so you you know you hit the drop down you get the list of options and you select one that's a combo box a list box is a box that has a list of presumably text in there but each one of those is interactable so instead of it just being like a text box where it's just straight text where you just read it list box can actually allow you to interact and select the cool thing too what you can do with the list box is you can select individual items or multiple items depending on how you code it they work exceedingly similar but there's minor distinctions mostly because the combo box you can only pick one thing in a drop down where the list box you can pick multiple objects and this is going to be that in my slide deck i don't like slide decks i prefer live demos even though they do tend to back to bite you every now and then so let's go ahead and see what this looks like in visual studio and so here i've made this beautiful not quite so beautiful ui but you've got a button and the button we can look at its properties the button is enabled as you can see so it's ready to go and i've given it the fairly complicated name of button i've done the same thing as well for the list box it's called list box and the combo box is called combo box not doing anything with the is enabled because we kind of went through that in the last demo uh but if you wanted to turn those on and off there's your check box and it sets that property it's fun but anyway and i've already went in and copied it over and pasted it into powershell and so there's demo two and see what we can see here is list box combo box and button uh incidentally what what does what the the parsing script does do and it's a good question so you can see when we've when we've created the names within visual studio xaml we see the syntax x colon name powershell does or the it doesn't powershell doesn't know what that means it will cause you to fail so what this is actually doing is we're taking our code and we are passing that to a variable here input xml actually and then what goes in from there is then that gets passed down here and what it's doing is doing a replace to get rid of all of the syntax that will cause the script to puke and that's really what it's doing that's one of the part of the part of that magic it's doing some checking in here too um what i also did to make this work a little more in an automated fashion let me go ahead and scroll down just a fuzz control to that and click all right so and this load objects uh i went ahead and tacked on an outnul because i don't really want to see all the names of the variables each time it's handy when you're doing debugging but don't need it for for day to day and then the other thing uh is throwing a pound sign or hashtag for you for you kids in front of the right host and they get variables so that just shuts it up last thing i did too is i went down to the bottom and actually declared the the commentary to cause the ui to load automatically so when we hit when we hit play on this one this is actually going to load we're not going to get a whole bunch of text that we don't care about now that we don't care about it but just not relevant anyway so we're gonna hit hit run and then assuming ise doesn't crash again hey it didn't now look at that so what does this thing do well we can see and i wish i could interact with this but i can only draw but we've got a list box here with string of text one two three i know it's terribly imaginative then we've also have a drop down green red yellow cool what does this do well let's go ahead and select a string of text and that's how this boxes work you know you can select one i set this up to be single selection and then i'm going to go ahead and pick a color i'm going to hit the button and see what it does ah string of text in green that's kind of cool let's play with this a little bit more so what if we take two and make yellow i look at that it took the different text and gave it a different color and predictably we can take a third and change the color and that works as well and so right there from a ui perspective we've given the user ability to select a subset and then a second subset of data in different forms and be able to take actions feasibly you could do something like let's say here's a list of users and we're going to go ahead and assign them to a department and then link go so depending on which makes sense you can use these but these are both exceedingly useful objects why why i'm blathering on about them so how do we make this magic happen fantastic question the the technique in here is a little bit more complicated but if you've been using powershell for a bit this shouldn't be a stretch i essentially and i'll say i cheated but i cheated to feed my data in i'm going to use an array you could just as easily have a function like like a get items or you know what the function is to find every file name in a folder or whatever you want to do recursively to compile a big list of whatever the data is that you want to work with and throw it at a variable name that's all you need to do this is just easy and gives a good visual of what i'm doing so here we go with this combo box go ahead adam were you going to oh did you hear that i only enabled my mic yeah i was going to to jump in at some point and ask a question it was like i saw that i saw your mic arm going up so i assumed you're well if you're sorry i may as well ask you now is um from chris chris kippel he um donna when you come back to make updates to your forms are you copying the xaml out from your ps1 into visual studio or are you saving your visual studio projects and coming back to edit forms he says it's an octoforp i use i'll copy it out of visual studio and into powershell i typically go one one way because i want to keep visual studio as a source of truth in case i lose my scripting sometimes i will go backwards like if i'm in wim witch and i'm developing something like oh crap i forgot to you know enable that checkbox i can go i can go and hit that really quick um actually you know where i do that all the time is in the version number because i always forget to change that in visual studio so it'll be like your version one nine two two and so i'll sometimes do that for minor but usually it's unidirectional at a visual studio um and into powershell cool i'll um i'll keep quiet when i mute my mic okay um is there any interesting oh that's okay was that is that the only question so far yeah i'll um i'll pop up one is another one yeah awesome so uh anyway um com using arrays to fill variables is what we're going to do here we can see there's red green yellow that feeds my combo box and then i've got string of text one two three which pop which i'm gonna use to populate the list box so how did we do that easily really using four each all the love for each boy was i what was i happy when i figured out how that one worked um so what we're doing is we're taking you know just a for reach so every variable within combo box array and here's where the syntax comes into play here oops crap i always keep hitting escape i don't mean to i mean to hit e so the syntax is is here is our our our object our combo box the wpf prefix and i'm using the the functionality items dot add what that's going to do it's going to add whatever you stick inside this parentheses as a discrete object within the combo box so what this is doing is it's taking you know the the combo box array and it's going green add green and then for the next add red and add yellow and that's how it goes ahead and populates each option within the combo box and realistically it works the same way with the list box it's using the same syntax um item.add and that goes ahead and populate your list box so yeah hopefully that kind of gives you a good idea how you can get that data in and how to start making it usable as a side note when you start messing with this if you don't put an out null in there which is you don't have to what it will do is it will output a number for each index that it's populating uh combo boxes and list boxes outside of having just the name of whatever you're sticking in there they actually have an index number so you don't have to remember that the first field is red it can be index one and that gets useful if you want to set a default like if we look when we loaded this form you notice how this combo box had nothing in there it's because you really want to set a step when you're in here to set the uh selected item to be index one i don't want to go down that code because it's introducing complexity but that's that's a well-documented thing it's easy to figure out if you can't ping me or you know go into wim which uh because everything i'm doing in here is in there um that's that's actually how my coding works is how the hell did i do that function from the squirrels oh there's the function copy paste change names i'm forever looking back at code i've written before because i i always think i've done that before we've um got one more question here from jason uh will the combo box dynamically add a scroll bar if you have more items that fit in the designated list box size ah i don't know i've never done it does that make sense i think the question is does it add a dynamically add a scroll bar i think that's more yes i don't know um i've i my combo boxes have only been like three out of three options so i've never reached that limit uh it's well within the possibility that it may not however i know from text boxes it doesn't that's one thing i had to figure out so you can do a scroll bar if we can see that there is a scroll bar option which i did use in wim which for putting in really long paths so you can scroll back and forth so short answer is i don't know but if it doesn't you have a scroll bar function that you can tack in on into your xaml if that's required well in that combo box you had a moment ago where's the code that gives you the selection so you can maybe just i don't know add a few more options and see what happens maybe yeah well let's go ahead and that's completely thrown you off i know it is i'm sorry boost that's just a curiosity you know well you know let's do this i know how we can cheat the system yeah let's let's go ahead and we're going to throw a comma and i'm going to go all right now let's see what it does there's your answer it looks like it does that's cool i'm gonna leave that there now that's awesome so thanks for pointing that one out actually the thought never occurred to me so it's cool that that's that functionality and this that actually makes me happy that's a good question jason thank you so how was so let's see what we're doing here so uh where did we leave off um populating so we did that yeah i think um it kind of ended on talking about yeah adding to the array and it piping out the index yeah yeah okay so yeah that's why we use the out and all to shut that up uh because you'll get numbers showing up yeah but that's what that's what that is if you see if you see that if you take that out and all off um so how do you actually use this um these combo boxes well how do you use those selected items it's actually pretty simple well list boxes and combo boxes have a property called selected item and that means exactly what it sounds like it's your selected item so in the combo box in our example if we select red red is a selected item um combo box or i'm sorry the list box would be your string of text combo box would be your color that's all we're doing is we're just taking you know our object and this particular property selected item and it'll pass it it'll pipe it through as a variable easy peasy list boxes you can do selected items so you can do multiples it just depends if you're supporting singular or plural which kind of comes down to your use case and really just looking at looking at this code you know we've all you know used write host and i'm using it because of the foreground color option makes it simple to understand so really what we're doing is calling right host and we're using the selected text from our list box our selected item and then using the selected item which is color uh i'm passing it the foreground color function so you should you can see here that if we you know the button we could actually have it called function pass username pass department and then it can go update like active directory or it could go do something or it could go i don't know make you a sandwich whatever your script does but with those objects selected you now have that data that you can pass to your to your algorithms your functions whatever you have to make your scripts work and so um i guess uh yeah that's that's kind of the extent of what i put together um i do have another script that i wrote for some for a client that doesn't fully work in here because he uses the task sequence environment uh yeah i mean i could show you that well yeah i mean jason actually came back with another follow-up question to that i don't think he actually meant the um the combo box i think he said the combo box but he came back and clarified he i think he actually meant the list box you know the one with the multi-select i think he's curious on if we added more items into that multi-select list does that produce a scroll bar i think that was what he meant i think uh i know how we can find that out yeah or something yeah we can do this instead i'll go to oh i'm not running this is administrator derp okay let me close that that would cause it yeah which is one of those solutions that you really need to run it as an admin powershell ise yes all right for those who haven't seen it this is this is my pet project this is my baby uh she does quite a quite a bit here um but boom there's my ui so you see there's check boxes text boxes scroll bar buttons uh what i wanted to look at though to test this theory oh i gotta select a source whim let's see what do i have here i think i imported a bunch for 1909 outgrid love this thing it's a lazy way to make a ui and that's not a bad thing i i don't mind something as long as it works all right so now we should be able to go ahead and select totally works good to know i thought that was the case but let me go ahead and just load it just for validation no that's um i hope hopefully that helps and um there there's a couple more questions selling in now actually um jason with another follow-up one [Music] he's curious to know if it's possible to make an item in your default or pre-selected or a pre-selected item in the list box i think what by the wording of that can you pre-select an item in that list as a sort of highlighted already and the user doesn't need you know can just hit okay and that item is already selected is that possible i would imagine so because you could call either the item or the index uh i'm not sure i've never tried i know you can do it with combo boxes because i actually do that with uh i do that i know you can do a combo box for sure but not that the idea hadn't occurred to me to try it with a list box i would imagine so you'd either needed to to do some type of thing where you know step through the list box and then say you know for each in list box if name is like then do or if you know you want to be item number one you could do index so it's possible i just don't know um where i've used it with the combo boxes here you know i default at either disabled and then i have a check going to see if it's config manager or going to be osd and then update the index depending on what the return is but yeah doing that with a combo box is very easy i've just never tried with the list the um presumably when we're pretty sure i see it but win which is on github so if people wanted to meet around on yeah just see what's what or at least i'll have a copy of it when they download it well yeah i have a github i don't use it and i haven't updated in like six months so if you really want to you use wim which is a as a as a pick it apart kind of thing um and laugh at my code i know everyone here is probably much better at powershell than i am if you go to oh i actually bought the domain name so i could just go to winwitch.com but for the for the time being we can go to ms endpoint you can also google win which will take you here tools there's wim wedge i'm starting to work on all the installation or all the the instructions we go to installation uh where is the there it is save script amen so yeah you can just do a safe script and download the script and then pick it apart it's all self-contained uh people have asked me for yours why don't you just make a module because i want to keep it all in one script uh the trainer fought behind the question was just that if these guys wanted to see um examples of how to do what you've done then they knew where to go for the source code absolutely yep yeah everything everything is in there everything that you've seen the day has been in use abusing tabs i've got you know various pop-ups for dotnet for you know doing um selecting files selecting folders there's a bunch other good stuff in there loading modules checking calling the powershell gallery that's all in there if you please feel free to pick apart my uh pick apart my um my code and if you see any improvements yeah i'm not shy you can tell me it sucks and what what needs to be what needs to be fixed awesome so we've got another question here from bash aminus bashaminus i think um say you need to populate a text box with the output of whatever function your button click performs would you need to redraw the form i've never been able to make this work so you would do something along the lines of oh let me go ahead and do uh one i know i had alex i got it and give me one sec to load this back up oh scripts and all right so what are we doing in this one again that is just to refresh my memory so what you can do you can do something along the lines of of this so let's see here so we're going to have where's our dialog box okay so you could do something kind of along the lines of this we're going to do wpf uh text text box dot text equals i actually know we could string this in ha this is a better idea so where's our button uh let's do this i'm just going to rem out the existing button code and then what i can do is wpf text box dot text equals now presumably what you would want to do is you know text box.text equals function and then function needs to return whatever whatever data set it's going to be but if we just close that and we'll go ahead and rerun this again to stick it in the memory and then we go ahead and do that and we go here the trick is just using that dot text because that's the property that's changing and not the whole object what do you think um the person meant by would you need to redraw the form i don't quite understand what that if you would need to cl if you would to if it was like a property change that doesn't update or on the fly so you would need to close it and then reopen it i think that might be more of like a legacy uh you know powershell forms where you would actually have to you know when you draw it out you're actually declaring all this code um but yeah you don't have to with wpf you can just tell the the text property of the text box what to equal and whatever you want to throw at it just throw at it and it'll take it that makes sense excellent okay um looks like there's one more question that's been awesome somewhat answered already in the in the chat by some people let's experience music but i definitely think it's a question worth asking you because maybe you've done it but the question is basically have you um packaged your ps1 script that generated a gui into an xc if you compiled it into an xe and distributed it to a to you know to focus on the help help desk have you done that before no i have i haven't um i i know like uh morris daly uh over at msn point has done that with driver automation tool um yeah i haven't really created an xc out of the script sort of thing okay yeah yeah then you have to get you know code signing certs and there's some other and then that sometimes gets flagged by antivirus i i don't know um like with wim witch i probably should but then i need to find some mechanism to go ahead and deploy or to store and have people download the axi and i just haven't gotten around to it um it's on the to-do but no i haven't done it well there was a pretty decent reply from the experience music says you can create a backfire that calls the ps1 i'm personally not a fan of that but if it's something that you're gonna share with you know help their staff that not might be completely alien to them i'm sure double clicking a back file or something they can do and also working around that code signing because that is a genuine pop-up and a warning that users get otherwise because you're right if you do compile into a certificate you do get that warning um someone suggested nigel suggested ps2xc i have used that before and um yeah that's what i would use if i ever went down there i know that it exists and i've heard good things about it i just haven't gotten around to it awesome that's uh that's pretty much the question so far so you said you've got this um script that you wrote for a client that's foreign maybe not everyone's familiar with config manager here is listening maybe just what's the task so what a task sequence is it's a it's a it's a sequence of tasks yeah that is defined and used to image computers essentially so yeah but the cool thing is each test you can put conditions so you can say if the computer's like this do this step if the computer is like that do this step and they can get extremely granular and extremely complicated and they're absolutely beautiful if you're starting it off they're terrifying as hell but once you start getting the hang of them boy are they exceedingly useful so anyway um what the purpose of this script was i had a client they wanted to have when they kick off the task sequence so they you know they do the f2 to boot and pixie and what they wanted to do because they have users all over the world and what they wanted to do was have the ability to have a ui pop-up to allow the technician to select what the language the installed what the language was and region was going to default to so my solution was hey i already wrote wim witch the win which handles language packs local experience packs the fods all that good stuff so let's just cram it all in there so everything windows would need is there and then the trick is just telling config manager how to make it work powershell so when i go ahead and execute this we're going to get an error because the comma object that calls the config manager task environment isn't loaded so just ignore the error and see and there it is but here this is where i compiled all of this information or used every well except the checkbox so if we look at this guy we've got a list box here and i pre-populated it with with our languages and regions and the reason why i have this in multiple steps is because i wanted to prevent a fat fingering from the technician because once the task sequence goes you really don't want to mess with it and you can't just go there's no back there's no backspace or undo once that goes it goes so what i did here is i said okay we're going to select japanese and then it's going to go ahead and populate it into the text box and then that's like that confirmation that i can hit okay now some of the code take away here is when i hit ok we notice the form closed by itself automatically so what i did in that case is that code segment exists here so like here's the the command to display the ui tacked at the very end this is the command to shut it and you can see it's all a dollar sign form that's the name of the variable that the entire form lives in and you're just telling the form what to do that way you can tell it to open and close i also stuck an exit code 0 in there so the task sequence engine knew that because it's looking for that that just makes it happy i guess without going into you know the gory details of it we can look oops um let me do that one again where else so you can see here just like i was doing before i once said an array of all the languages and i went ahead and populated my list box with all the languages just like i did in the other one there's the out null to keep it from squawking but in this case though we see the button we have the add click what i'm doing to actually find to get which variable has been selected i'm setting this variable here and i'm calling a function set language and i've got that up here and it's just some basic stuff you know the the selected lang is the what is going to end up getting returned back out of the function so i set a default just in case they hit they hit x and it somehow muddles through at least it doesn't just throw up all over itself but really all it's doing is you can see it's doing a comparative of looking at the the text box there's your selected language the name of that text box where it goes and writes it to and dot text so i'm just doing a comparative and setting the variable name or setting you know this probably in this variable based off of whatever exists in the text box nothing crazy it's kind of just an extension of i've been blathering about over the last hour um so does the comparative sets the value based off of whatever is in that text box returns returns selected lang then that comes down and that gets kicked over to variable and lastly this this is actually a variable within the task sequence that's outside of powershell but this whole process allows you to take data out of powershell and pass it into native task sequence objects so you can then take actions because the test sequence variables allow you to set conditions so you can say in this case custom dot and your custom underscore lang is now either going to be en us eses esmx or jhap and then in the test sequence i can say if custom lang is esmx do this step if it's enus do this step and then i've got all the the keyboard and the language and all that time zone all that stuff set there and so it's kind of an extension of all that stuff that i just you know went through today and actually you know building hours against it so i mean it's building a basic ui once you get the general gist of it you can become really popular for for people because oh yeah i need to i need something to take data in here like okay cool well yeah that's going to be eight hours of billable work and i'm just sitting here in powershell and i got star trek going and a cup of coffee and the printer's going and you come back like wow this is exactly what i wanted and it's like it wasn't that difficult um it's a good skill set to have it really is uh that was uh that was tremendous that was some that was really insightful i think that was a great introduction i've never really given gooeys the time of day and i don't know why it was that was i can't see why i wouldn't that was a very nice icebreaker excellent and just remember just as the follow-up if you if you do nothing else go here if you want to learn um since that is the absolute resource steven's the man he's done his song song and dance at mms and all sorts of other microsoft stuff so for further you really want to take it up do that you can also ping me i'm on twitter um yeah did i put that in the slide deck i may have uh at notorious drr yeah your twitter handle is on the title of the video i think if not it's definitely in the description so if you guys have any questions that you want to follow up with i'm sure you can hear me yeah please do i suppose you've ever heard of like um i've heard this before metro gui building like that's a thing right without gui building metro stuff yeah yeah because uh and i forget the names of the folks involved because i have no short-term memory or lost my long-term memory too it's all filled with config manager and use of star trek trivia um but yeah there's there's a process there's a whole project called my apps it's m-a-h apps and then what they're doing and i've looked at it because actually um and i feel bad because i don't i'm gonna say his first name is jerome but i could be completely wrong but he pinged me he's like hey i took wim witch and i applied this to it i'm like damn that's sexy yeah cause like he had all the the tabs were loaded down the left side and there's only smooth transitions the only problem with it though the reason why i didn't adopt it is because there's a dll that drives all this graphic stuff and since i'm pulling this down as a single ps1 file out of powershell gallery that's not compatible unless i wanted to have an external dependency to say you know go detect dll if dll is not then go download and load if dll does not load then fall back and use it like it's just not worth it so what's the dependency with wpf then is it dot net based i think i heard someone say that earlier it is based right and is there like a minimum version that you know of that needs to exist for it to function as a bare minimum uh i think three it could go earlier i'm using yeah i'm using five yeah i'm using this will run in powershell three like wim which runs in powershell three except for parts of it that don't like a ps script root that exists in powershell five so i have to set a minimum level of five so ps script roots because i have no idea where people install wim which half the time it's in downloads which is a bad idea um because you'll end up having you know 25 gigs worth of os os media and updates and binaries just hanging out in your user profile but that's what my apps it's cool if you're not going to be doing something where i need to stick to one file absolutely check it out it is so cool it it puts so much polish onto a project it is it is it is really sexy it's very sexy now that was really good thank you so much i really appreciate you coming on to to do that for us it was um really engaging really really good i hope everyone else enjoyed it i know i definitely did thank you all so much for um tuning in before i wrap up is there anything else you wanted to to mention donna i don't think so please do if you got questions comments whatever follow up ping me on twitter if you want if you don't want to make it public i do have my direct messages open which can be dangerous but no one's taken advantage of that yet so we'll leave it that way until the ugly side of twitter figures that out but yeah please if you got questions and i guess the last takeaway is again if you're on the fence or you're scared to start this isn't that difficult you can do it you can absolutely do it excellent fantastic brilliant well thanks again donna um welcome the recordings i say would be available for tomorrow um we powershell something does want to make a call for speakers so if anybody has a topic in mind that they wish to present um anything at all you know please get in touch with me um and we can arrange something i just want to say thanks to chris kibble for help behind the scenes getting this up for me um and subscribe to our youtube channel if you haven't already that way you can find out when we go live and like i say you can catch the recording for tomorrow and look back at our other sessions as well and the next session if i just change scene you will be able to see that the next session is tomorrow night same time with josh stephanie and he is doing uh using ansible with azure live so if you don't know what ansible is you want to break in and you want to break in with it using or on azure come along [Music] it'll be really good really really good so yeah thanks everyone and take care stay safe thank you thank you
Info
Channel: PowerShell Southampton
Views: 2,945
Rating: 4.9259257 out of 5
Keywords: powershell, virtual event
Id: KD5XAx7t-J8
Channel Id: undefined
Length: 64min 20sec (3860 seconds)
Published: Thu Oct 01 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.