PowerShell on macOS – John Welch

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
rigged it up okay so session Powershell and Mac OS I'm John Welch I'm a Senior Systems administrator with Honeywell in Kansas City I've been a part of the Mac it world since the late 1990s grow up on things like net octopus very early versions of file wave pre-casper before it became just jamf um anyone remember Apple share IP a lot of work on that so I've been I've been doing this for a while some of you know me I may have had some opinions on installers automation user interface once or twice um one of the first things I really did interesting with management tools was I was using that octopus and I realized they had an amazing applescript dictionary to where I could actually script registry changes on NT server 4 from applescript it was kind of crazy a little bit weird but it was very cool uh anyway you remember Sal sugoi and I showed him that and how you could take down an NT box just by deleting registry keys one after the other he said I was absolutely evil and we got along really great after that um today's topic is something that that has existed for a while but it's very much underappreciated so I'm and I really dig it as a tool which is Powershell on Mac OS yes Powershell um it's been around for a while now it's updated fairly regularly um just a heads up in 60 to 75 minutes we're not doing a deep dive you are not going to come out of here knowing a lot about a lot about Powershell how to do stuff but about what you can do with it is kind of my goal here um when it comes to time really indifferent at the end of the day the tool does the job correctly for the job I needed to do and the context the job exists in it's a good tool if it doesn't then it's not a good tool I like having an access I like having access to a wide range of tools it just gives me better options there is no one true tool even though the Mac it Community is is vulnerable to that sort of thinking as any other community within Windows you know InTune SCCM is the one true tool I have done a lot of work with other windows admins getting them to realize that even Powershell is an acceptable substitute for dos language especially if you're doing ad stuff the workarounds those guys will go through to avoid Powershell and one line of code is amazing um every tool has its positive and negatives and it very much depends on the context so it works in one situation is absolute bad in another a more formal way of putting it is this quote here and this comes from a book called range by David Epstein um and if it's it's basically a book of why generalists do really well in a specialized world um the more you know the wider your range of knowledge the higher chance you have of solving the problems and one of the examples in the book was when the Exxon Valdez oil spill happened in Alaska one of the problems they had was when you pull oil out of basically frozen water it's sludge so they can get it out of the ocean into the boats but they couldn't pump it out of the boats really easy because it's basically peanut butter at that point and so one of the first examples of crowdsourcing they put it out on the internet how do we fix this because they have all these petroleum Engineers but they're going at it from a petroleum engineer point of view so they really don't understand how to fix this and this guy who had never done anything with oil petroleum or any sort of chemical engineering but he had worked a construction job when he was in high school and one of the problems he had was they had a cement truck down at the bottom of a hill and they had to get the cement up to the top of the hill and they couldn't pipe it up they'd be doing wheelbarrows cement sets rather quickly but with the way they prevented that you can get these things at Home Depots you basically take an electric motor or gas motor an off-center cylindrical ride about three feet long you shove it down into concrete hit the button it starts jiggling really fast and it keeps the cement from settling so he said why don't you try that and they did except they did a super tanker size one shoved it down to a hole full of peanut butter and it liquefied the oil that fast sometimes the weird Solutions are the ones that work like Powershell um background it's been generally available on Mac OS since 2018. started with Powershell course 6.0 that was very limited the current version is in the sevens much more future complete it also works well with dotnet 6.x 7.x.net 8.x is in public beta so you can actually do a lot Beyond just general Powershell stuff you can bring in a lot of.net stuff too which is a huge help versions long-term is 7.2 the stable is 7.3 the preview is currently on 7.4 I think they just dropped 745. um it's available both on Intel and apple silicon along with net 6 and 7 and eventually eight are also native for Intel or apple silicon so you don't have to worry about um dealing with that nonsense ported OS versions on Intel 10.13 on Apple silicon Mac OS 11 and later you can get it that's the primary Powershell GitHub for Microsoft right there Powershell Powershell it's also available via Homebrew so you can use cast to install it I cannot remember if Mac ports has it I do not believe they do obviously there's some differences from Windows there's no windows specific items so you don't have any of the wmi commands the cim commands because that literally does not exist on Mac OS there's a very handy command in Windows called get computer info which gives you all this active directory and registry info that has doesn't exist on Mac OS so that doesn't exist either there's no application scripting office only supports Apple script or VBA unless you're talking about Outlook in which they have a very old and desperately need of update applescript dictionary because it doesn't recognize ms365 accounts they should fix that um there's some other things that don't that don't exist that exist on Windows like Powershell Diagnostics some job scheduling things obviously it is not a shipping component of Mac OS I I don't feel like that needs to be said but I've had a couple people go I can't find it I'm like did you install it no okay step one um there's a lot of built-in functionality a lot of azure AWS modules and I mean a lot of so as it turns out the AWS team uses a lot of Powershell on Linux well Powershell on Linux Powershell and Mac OS are very similar so all the modules that work on Linux also tend to work on Mac OS so you get an insane amount of AWS modules for free a lot of the Azure modules the official ones work really well on Mac OS um also remoting via SSH so you can I you can connect to other windows machines and servers via a variety of methods you can also connect to other Unix based machines Linux servers Mac OS desktops if you want um it supports SSH keys that kind of thing it integrates really well with shell and apple script um one of the problems that Powershell has on any platform but especially on Mac OS is that there's not a lot of if you want it like on Windows do like a display dialog or have someone choose from a list you are doing a lot of work building that dialogue by hand you can't just say choose from list here's a bunch of options but what you can do is if you use Osa script inside of Powershell you can feed it display dialogue choose application choose from list and you know you set a variable to it and it'll spit the results back out into the variable so you can you can take advantage of the applescript UI Primitives with Powershell and you don't have to do all the work yourself basically any shell command you can run without a whole lot of work at all Powershell also has some Unix semantics so things like LS CD that kind of thing not you're not going to do like shell scripting and Powershell I don't know why you'd want to but you can you can get a lot of the basics done without having to learn the Apple the uh The Bash versions The Powershell versions you can just use a shell there's probably more that was around a month ago when I last look if you go to Powershell gallery that is where all of this exists most of the modules there's about 700 there they're all very useful there's even some jamf stuff in there and I mean really and I'll demonstrate this later you can write Powershell modules in Powershell so if you want if you're using kanji and there's some command line utilities you want to wrap into something else absolutely you can wrap it into Powershell make it a module you're good to go very portable there is no weird directories once you get to user local Microsoft Powershell the version number that's the entire Powershell install so technically you can if you're building an app you can take that Powershell directory shove it into the resources folder within the app bundle and you now have access to Powershell within your app I am not a lawyer I have no idea what the licensing implications of this are or if it's allowable at all please go talk to a lawyer about lawyer things not assisted men because I will give you at best not correct advice which with lawyer stuff is expensive it's highly extensible as I said one of the big advantages of Powershell is you can write Powershell modules in Powershell you don't have to see or anything else I talked earlier about that get computer info module for Windows I wrote in an analog of it called get Mac info I'll show it to you here in a second um it uses some built-in Powershell features it uses some shell script commands it uses Apple script it just it was partially that was the best way to get it done but it was also a neat demo of how Powershell can talk to anything um so you get a lot of functionality at all levels of the OS in one place and as we'll see powershell's syntax is remarkably nice compared to about everything else so let me shell out of this and where is ah there you are visual studio code so this is get Mac info there's a bunch of stuff going here it grabs stuff out of um oh okay yeah let me slide it over thank you there's a lot of stuff going on there um it pulls stuff out of system profiler it pulls stuff out of I have started adding Apple silicone code into it it's still a little wonky I don't actually have a apple silicon Mac um assist control Apple script stuff like that so and because I have it as a module I don't have to do anything special I can just do get Mac oh look there it is hit enter it's going to think about it bring that up a bit and so here's all kinds of useful info on my Mac right there but because Powershell is is a very kind of a training wheels object-oriented language you can do some neat stuff with it so let's have let's assign that a variable okay it's going to do its thing so now if I do we see the same thing but let's say I just want um boot device right so I do oh wait forgot of course I did so if I want to just use certain parts of that in another script I just shove it into the variable and then if I just want the boot device I don't have to do a lot of said grep text parsing it's just the part I care about right there and that's your that's your object syntax in Powershell is is variable dot parameter um so that's kind of Handy you know especially you know the less yes said and grep and all those are very good but if you don't have to do that constantly because you're not dealing with the language that thinks everything is a string it's kind of Handy this is up on my GitHub and I have links to that at the end of the freezo um but yeah as I alluded to it understands a wide variety of data types natively so it actually has built-in commands for specifically dealing with comma separated values you don't have to do a lot of parsing for that I do that um at work on I manage license servers for things like Autodesk software SolidWorks things like that out of roaming license servers we have a monitoring system for that that when someone logs in to use an app it grabs their user ID but it doesn't grab their name their email and anything else but that's all an active directory so what I do is I do an active directory poll pull out the right info turn that in and to get the department number that I need I import a comma separated list that's got all the departments on it with the actual department number and then the department number that the tool I use uses internally and I just go down to that to pull Department numbers but that's literally import CSV you can assign the headers to whichever field you want there's no again you're not parsing the text directly you're dealing with it as a series of fields Json XML there is a ton of Json in XML features commands built into Powershell it has built-in object types like actual object types not kind of trying to pretend like an array is a big texturing type thing you can make your own custom classes we'll see a little bit later if I have the time so you can create your own object types including functions within the class like you can really do it up and you don't you're not leaving Powershell at any time to do that you can do that all within the language multiple listing array types it does generic it does um Regular arrays it does what would in apple speak be mutable arrays it does key value pairs all of it and again you can customize it if you need to um the nice thing is it's not just parsing text until you want to jump in front of a truck there's also Advantage you can also bring in stuff directly from.net if you have.net installed on the machine you're running the script on you now get a lot of the.net feature set on your Mac so you can do even more stuff um you can directly if now again what's supported on.net on the Mac would support it on.net on Windows obviously very different things there's just things that don't exist for some odd reason they haven't I hope they fix this there's none of the the UI tools sets that are in.net so you really do have to use like applescript or something else if you want a UI in front of your Powershell script um but you get a lot of that and so like one thing I was talking about before vs code so this is the thing um if you haven't if you don't know um Rich trouten he's here today uh this is a Powershell version of a script he wrote that basically goes in grabs all the available software updates for a machine listed out with an index number uh the name and the version and use it uses the version to actually pull down the update you want it doesn't install it it just downloads it um I thought that would be a cool thing to to move over to Powershell partially for this but also just because I do that sometimes that's how I learned how to do interesting things on Powershell but the problem was is that there's a lot of like you'll have like for Monterey you're going to have like seven things that are Monterey Monterey Monterey so if you're trying to do say a hash table in Powershell which is just a list of key value pairs there's repeating things so it just doesn't play errors out there's a lot of ways around it I could have appended stuff onto the name I could have done like an array with individual sets of key value Pairs and just made myself crazy with it or I could do what I did there which is I created a class called OS update which has three strings the title the index which you use to pick the version you want and the version number and that just gets shoved in there so it goes along it runs the command software update listful installers it removes the first two lines because that's garbage that I don't really need for the script and it's two lines so I just did each line individually just kept removing the first line until I get what I want um then it goes through each individual item in the uh arraylist which is set up as a a mutable array um and array actually in Powershell it's an arraylist and it just starts pulling things from it it pulls the it creates a string array it pulls the title it pulls the version number pulls out any um leading spaces okay and then there's some weird stuff in here because as it turns out the the read host step which is how you get the user input and command line if you don't do things in a certain way it will it will block the right host commands that tell people what to enter so it's like it's waiting for you to enter stuff and as soon as you hit anything and hit enter then it shows you all the stuff you needed to see what you actually were trying to enter so that's that's a little dysfunctional there but wait let me move this back up the nice thing I love about vs code is you it's it's also a great text test environment so like to do see it should work yeah see and here's where hitting the read host thing so I got a couple of bugs there but if I hit like three it's going to start trying to download that yeah bugs are fun but that's general idea but the nice thing is by being be because I can create a custom class I don't have to do a lot of weird workarounds to make up for the weaknesses in other data structures I just created my own and that's something that's you can do in things like python to a certain extent you can I imagine you could fake it in bash I just wouldn't want to like that definitely hits the diminishing returns level and it's nice that it's a built-in feature so you can do this you can have these things listed out you can build modules with your custom classes in it and just refer back to them so if you have a bunch of custom classes you use you create a module and the the get Mac info module is again up on my Powershell site creating modules is a little tricky but it's not too bad and you can then have those available whenever you need them it is syntactically similar to c-sharp and as I said there's some Unix semantics in there this is one place where Microsoft is cleaning Apple's clock in two ways first of all Powershell on Windows is a coherent OS wide from bottom to top automation framework the last time Apple had an osy coherent single automation framework was Mac OS 9. they've never had one in 10. it's always been a Pastiche of little shell little apple script little this little then you need to stitch it all together and now you have a drinking problem uh the other thing is because Powershell is based on c-sharp the more you use Powershell the more familiar you are with c-sharp syntax especially as you start importing c-sharp modules you're learning C sharp without learning C sharp this came in really handy because as I said I at work I manage something like 13 14 license servers all windows or one Linux that each is running anywhere between 4 to 12 licensed Services individually we're trying to monitor that through solarwinds it's really tricky part of the problem is is the way solarwinds monitors things is the way a lot of network monitoring systems monitor things all it does is say hey is this service running if the answer is yes it's good well is anyone here as doll with especially like in the early days of httpd you can have the demon running and it's completely deaf so yes from the machine side everything's fine but the outside world is like there's no web server here there's no website so what I did was I had I had this long Powershell script that lets you pick the server and then it it uses external executables to query the License Services the way the clients went from the outside so the port it's looking for specific responses things like that if there's not an executable I can at least test to see if there's anything listening on the correct TCP Port so at least I know there's something there I decided for my boss and for other people who wanted to do this without dealing with you know for a lot of people the command line is legitimately intimidating so I built a GUI version of it well it's on Windows obviously I'm going to use visual studio and c-sharp with it because that's you know and what I discovered was is because I'd done all this work in Powershell the documentation for the c-sharp equivalence was really easy to access building it out in C sharp was really easy the hardest part was where apple is cleaning Microsoft's clock is in building uis within your app and having it look the way when you run it the way it does when you're building it because let me tell you in Visual Studio those two things do not sync up well at all so it's like okay this looks good oh look all the dialog fields are overlapping okay let me start move it move it move it okay no no yeah that was not fun um for anybody interested Visual Studio does exist on Mac OS it is fairly full featured you can build Windows apps from within from a Mac that's kind of terrifying and weird but you can do it you still need xcode for some things and I last I checked it doesn't support Swift UI yet I'm not surprised I imagine getting that to work with a completely separate IDE will be a little work a little tricky but you can Visual Studio let you build iOS iPad OS watch you know the whole feature set that's Visual Studio not Visual Studio code big difference another place Microsoft just runs over Apple um excellent documentation I mean Beyond Apple doesn't have anything close to this um let me see here so this is the main Powershell documentation site it has you know downloading everything you'd want they also support the community really really well um like they have regular calls for the community there's a couple of Powershell sites powershell.com I think don't quote me on that one that are Community sites for helping people Microsoft is all in on that they have a lot of they have people dedicated like the Powershell team is massive at Microsoft um they've got you know like I said all kinds of resources there's a site Microsoft's had for years they recently got rid of it because the one guy was running it retired and they decided to fold it into the larger Powershell Community but if you ever heard of hey scripting guy this was like one or two people at Microsoft and you would just post on the site or you'd email them hey I'm having this problem with VBA or Powershell or whatever what's going on and he just answered your question he would hand you the answer Microsoft paid this dude to help people who did automation who weren't coders they were just people trying to stitch word together right I have been dealing with apple scripts since System 7 Pro when it first showed up I have never seen Apple do that and I don't think they ever will it's not a question of resources they just don't care at this point it's the only on it's the only explanation um in terms of documentation so you can pick anything uh yeah so out host this is what you get and this is for every Powershell command you can find and you can choose by Powershell version including betas including very old versions and you get sample code you get what it should look like and it goes through all the parameters explains what it is you can then link to that and this is for everything it's not just for a couple of things who here has gone to like Apple's developer docs and all they have is the name of the of the statement it's like it does this how how pray tell does it do this could you share this with us that doesn't happen again apple is a three trillion dollar company I think they can hire a couple of tech writers who aren't crispring Chris does a great job but he can't do everything um related links the whole thing and this is for all of this like the detail on this you can search you can search through different versions of things and it's all right there and this this I live on this site because I've got so many links to this for stuff I use because that way I don't have to remember everything it's just right there um honestly I think apple has a bit of a if you're you know real devs don't need documentation thing going on I haven't seen a whole lot to dispute that there's there's a lot of ego at Apple gee there's a shock Powershell Community is highly supported by Microsoft they bring people in on the reg to talk about what they want from Powershell they go out and visit with people are using Powershell in interesting ways they love it one of their biggest one of their biggest requests is if you start using Powershell on a Mac please let the Powershell team know because they're kind of in the dark as far as say you know it's Windows Linux and the Mac exists they have no idea about usage so if you do start using this please manage to let somehow someone on the Powershell team know they'll love you um they really actively engage I've gone to ignite a few times the Powershell team will sit there and talk to you all day long they do way more than just ignoring bug reports as I said it's cross-platform it's at least this cross-platform is shell a little bit more in terms of syntax it's far more consistent a built-in command is not going to have really radically different syntax between platforms the Powershell Community is very insistent that if you're going to do your own command you're going to write your own C code whatever to create your own command that doesn't exist that you do it the right way there's a structure follow the structure they're not awful about it but they can get a little snippy if you don't do it the right way this this is so consistent the commands basically every command and Powershell unless it's a one word command and I don't think there's a lot of those our verb noun combinations all switches are preceded by a dash all variables start with the dollar sign um if you're using an object it's object Dot data member arrays you can use braces you can use parentheses depending on your setup array you can use dot notation um if you use a race syntax in almost any language Powershell has zero surprises for you I love not being surprised um so one of the things in vs code is they actually have a Powershell Explorer give it a second here and it'll list up that's what it is it's add something add Dash noun there's uh get Dash noun set like you've got a couple of really small things those tend to be the unixie type stuff add type add member clear git set the verbs are really obvious and again the Powershell site will absolutely walk you through learning how all this works and because they have really good documentation if you're curious as to how a command works it will tell you these things um it's also got some good built-in help for things they actually have a built-in help command called get help so like let's just say that even though I wrote the module I forgot how get Mac info works so there this is and you can create different levels of Health mind you okay and there it is you can write your own help you can actually update it you can set up a website with more help so if somebody if someone's if you've updated your help data it'll update it within the command when someone tries to get to it and you can be very detailed in it you can include some syntax demonstrations all that yeah when Apple went to the p-list for the SDF files for scripting dictionaries that you could do that you could have syntax demos within the dictionary so people would know how to use a command almost no one does it and God knows Apple doesn't because Apple won't dog food anything outside of the newest Swift toy but that is that is one of the great things about Powershell is once you get that that verb noun combination you're halfway and they don't even have a whole lot of verbs um they they've you know it's a it's a really small number of verbs so you don't you're not memorizing a long list of things and as it turns out even though Google is a mess for finding things these days if you type a command if you type in like git help Powershell it'll take one of the first links will be the Microsoft page on it so that's kind of Handy there's a free cross-platform IDE Visual Studio code I'm a long-term BB edit person I love me some BB edit I really do but if you're going to do Powershell use vs code two reasons one it integrates with Powershell better than anything out there on any platform okay two it's again it runs yes it's electron electron is awful we can all agree but it's not the worst electron app and it runs the same way on Windows as it does on Mac OS as it does on Linux so the muscle memory you build using vs code here will apply there this is kind of cool again links uh this is my site looking for Powershell I've tried to write a lot of stuff on there with some how to's about things if you search for Powershell you'll find almost all of it I've got a couple of repositories um like like the one I did with uh Powershell display dialogue where is where is there it is and the nice thing is unlike applescript GitHub actually kind of understands Powershell so like oh look there's the code um but it's it's it's pretty much what you expect display dialogue blah blah blah pipe it to user binosa script um that's there's some Powershell quirks that sometimes you find yourself having to work around like for example if I want to run a process in Powershell there's about three ways to do it one is that where I take the parameters I pipe it to the command I get the results there's also start process which is a little bit more involved you can you can do some error handling within it that kind of thing and there's invoke process which is similar to start process but slightly different in terms of how it works I mean Powershell does have its moments it's not perfect but you know this is again one of those things where I can just do the thing and I can pull out the dialogue reply which will have the button I clicked and whatever message I typed in the text field with two choose file you can do that with uh choose folder choose from list and it'll spit this all out um back go back some more um see what's next because okay so before we hit the Q a let me dump back in here so one of the things as I was saying is that you can do a lot within Powershell to talk to different things and so so there's the invoke inspection invoke expression for CIS control because that's the best way to get that data out of that um and it's about what you expect in Vogue expression Dash command there's all your parameters if you start process um it's better for more complicated things but you put the executable name the command name and then the parameters in two separate um Flags um but then what I'm doing once I get it out is I'm splitting the results so and when you run split it converts the string into an array of strings with each field based on what you choose as a split character so already you've gone from trying to grip through a string oh no I've got all my Fields as an array so that's a little bit easier and then again there's a lot of that FD setup for that I mean and this is again all this stuff is just generic commands they're all generic Mac commands I'm just shoving them I'm just using them Powershell and shoving them into Powershell variables there's no real surprises here but this is letting me link so many things together in one coherent format um in case you can't tell I am absolutely willing to flood a script with comments because I like going back to things two years later and knowing what was going on and weird that way so this is a fun one anyone using Powershell on Windows get up time only showed up in the seven in the Powershell seven thing if you want to use with Powershell five one which is the default version that ships on Windows to get uptime you're doing a bunch of wmi commands and parsing yeah the output of that and I really wish they would back Port get up time to 5.1 because that is so tedious you know and then we're just and so you can have and this is all a hash table here where I'm shoving things in there but I can also do as a sorted hash table so when it spits it out it's already sorted in alphabetical order I don't have to do any work it's just how I create the hash table kind of Handy you know and there's it's doing all this little table layout and stuff like that like like and again this is I'm not haha bashing on any particular language Apple I anyone knows me I have again been in applescript fan for a long time I think it's a very underrated language it's it's really easy to read and for people who especially someone like a heavy SQL background SQL to applescript is a heck of a lot easier than sequels almost anything else there's no weird dot notation which from a SQL point of view is weird there's not a lot of that um Powershell is kind of like that for me it I don't the the syntax is so consistent although I do have an article about application scripting and it Compares doing the same thing in Excel I think on a Mac with applescript and on windows with Powershell and what you realize is if you're doing any kind of application scripting any kind of syntax uh regularity that you're expecting just gets thrown out the window because you're dealing with application innards application innards are all weird and the same thing like you could have literally almost the same statement in word versus Excel and they mean completely different things like for example anyone use format is table in Excel when you just want to be able to sort stuff real easy okay that's not actually a table in Excel that is a format that's a style internally if you're trying to and I have to do this with one script um because I realized where I worked there was no official list of department names and numbers so I have to go anyone ever use microstrategy big it's a big Enterprise query tool so it spits out this I basically download every employee with their department and division names and numbers and I just I abuse an Excel file to an ungodly degree so I get a CSV that has undo you know and it gets rid of duplicates about his department number in the department name the division number and the division name and then I shove that up into confluence you can use by the way if you anyone here have to use confluence there's Powershell modules that let you shove attachments and all kinds of things up into Confluence so if you're going to build a Confluence page and you're using their enhanced tables which lets you use a CSV file as a source of the table data which is what I do you can just show you can you can write a script that if you're updating it periodically it just shoves the CSV file up in there and as long as the name's the same it just overwrites the old ones you always have fresh data um that was a lot easier so now the only manual part of that entire process is downloading the original Excel file but I wanted to format it as a table so I could sort things and that's when I discovered format is table is a view style not an actual table that took a while that was annoying um but yeah so you can you can really do a lot with it I would not want the office team to abandon applescript but if they were to replace VBA with Powershell or maybe add Powershell in there I would also not complain about that VBA is nice but it has its weird moments syntax is very VBA is very old so the syntax is very old and it reflects that in a lot of its inconsistencies there is a lot of Powershell support out there um stack Overflow has a crazy number of Powershell answers the only thing I'll say is if you're new to Powershell that a lot of the people who answer questions on stack Overflow are very familiar with Powershell and so they use a lot of the built-in abbreviations they put a lot of stuff just on one line so sometimes you got to kind of get different answers to see how people do it a little bit differently and compare that with the actual syntax that the commands are using to kind of figure out what they're doing partial one of the weirdnesses is you can use like dot underscore for like a local reference to something and if you don't know that you're like what are you doing I don't know what you're talking about here there's no variable name Visual Studio code to its credit if it sees a place where you can do that will actually um flash you up a warning where you can it also in addition to syntax coloring it does a small amount of Sanity checks on your code so if you have an obvious syntax error it'll flag that in red if you're not using a variable it'll throw a yellow underline on it so you can say I don't need this because I'm not using it anywhere in my code comment it out do whatever um if you've got equality order not so much wrong but sub-optimal it'll tell you hey you should reverse this because maybe going forward in the language the old way won't work anymore so there's a lot of help there um it's I mean for a free text editor programmers editor it did for Powershell again it is absolutely the best thing I've seen I've not seen anything come close so we have some time for Q a or you can do some more weird demos um okay let's do some demos so when I was talking about creating modules where is okay so get Mac info this is actually the module there's a number of files um to create a Powershell module and by the way you can put modules in three places on a Mac you can put in the home directory for the person so it's only available for that person so if you've got local admin accounts on a machine and you don't want certain things available to everybody you can put it in there you can make it available to everybody on the machine you can also put Powershell modules on your network so if you have to bounce from machine to machine you don't want to copy things down or try to put that in your deployment tree you just want them available you can throw it up on the network and as long as it can see the mount it can use the module I do that a lot at work but so there's Pia in a module the psm1 file is your actual code that's the PS1 file version in the module right if we go back here this was the one thing where I really think they need to up their documentation figuring out how to build modules will make you old it is not this is one of those things I think over the years the majority of the Powershell Community just kind of knows this and so they haven't documented well for people who don't um but here's where you the the psd1 file is where you actually do your your support work in there um module versions copyrights descriptions minimum version of Powershell which again given that there are several versions of Powershell out there kind of Handy professional you know architecture.net framework on a lot of this obviously would apply more on Windows where you're dealing with you know who here gets to play.net downloadable visual C plus plus runtime module hell that's awesome I I will say this for apple and I've I I've said if Microsoft wants to seal something the application bundle concept would be an amazing thing to steal because when I show people at work how so here's all the special libraries required by word they're in the word bundle they don't exist anywhere else well isn't that a lot of duplication of code yeah you know what I do to uninstall it delete that's it yeah I don't need an uninstaller dude like literally there's the application bundles the auto updater goes over here in library application support and I have pretty much described the entire office installation on a Mac if anyone's ever tried to go rooting through a registry Hive or even just figuring out so is this in program data in this parts and user data roaming but this part has to be in user data local oh and I need this over here in user data local low oh we're using network mounts with ad so this is actually over here on the network and oh my God I I will give the package bundle format which took me a long time to kind of grock the to be honest I didn't Rock the Brilliance of it until I went back into heavy Windows admin and I'm dealing with um so there's a cad 3D application called SolidWorks SolidWorks 2020 wants VBA six point something SolidWorks 2022 wants VBA 7 the downloadable modules if you install 20 21st and then install 2022 everything's copacetic but if you do it the other way because SolidWorks is kind of like InDesign their file format is really kind of a database type thing so you can't back Port easily so you're working in SolidWorks 22 you're doing your little build thing and all that but now you have a customer who only has SolidWorks 2020 and they don't want to pay and if anyone's dealt with high-end Cam and CAD apps those are expensive like anyone here deal with Matlab anyone deal with the difference in Matlab toolbox costs between roaming and local it's a factor of 10 you basically take your toolbox cost for like a one personally license multiply it by 10 and that's what it costs for roaming Matlab budgets are insane so Solo versus kind of like that so they've got 2022 they want to install 2020 you have to uninstall 2022 and then install 2020 and you have to make sure that VBA module gets uninstalled too because as we all know with Windows because everybody's oh there's already this runtime here I don't need to install my own I'll just use this one while I'm uninstalling it I need to uninstall this runtime look I broke three applications I will bag on Apple for specific things but there are also places where they make our life so much easier and not dealing with the runtime hell that is Windows is a huge one also if you've ever tried to command line uninstall anything and like really totally truly uninstall it you're going to be using Powershell anyways a lot of Powershell and installing AutoCAD is is an adventure um anyway here's the Labyrinth it's the bug of infinite stench it quite literally is there's there's no other way to put it it is the bog um but yeah there's there's that um like I said feel free if you have any questions email me I try to get to things as I can um think I'm I'm fairly easy to find if you need to find me um Jay Welch at binkybynki.com is the email I use for most things um oh the best yeah so there's a site called 20 ties that has stuff like this for you know ties twenty dollars stuff like that there's a lot of very cheap vests I think this was like fourteen dollars um I got into it um as far as the time I goes there's a channel YouTube channel run by a dude named Patrick Novotny he's got 150 tie knots and he walks you through each of them this is a tool if not um everybody's probably seen the Eldridge and The Trinity he goes way beyond that he's got one that looks like an hourglass knot I mean there's some really amazing stuff out there he's got um but yeah that's how that's how I do the toe thing so if no one's got any questions I mean we got oh does script signing work the same way as it does in Windows I think you would use different I think a sign script if it's as long as everything is copacetic on Windows and the Mac version can get to it it should work but signing it on the Mac would be very different just because apple and the OS in the file system handle signing differently I'm not saying you can't I'm just saying it's going to be different um doing it especially if you have A.D set up right for signing certs is like a one statement thing um I have not tried to do it I'll say that I probably should at some point back now um can you talk a little bit about uh best practices for Distributing Powershell the executable to client machines if you were if you wanted to use Powershell to you know to script things sure so when you download Powershell regardless version It's a generic installer package so you can you can deploy that with whatever um in general the versions there's not a huge amount of differences I have not seen anything really break usually you know there's there's like security updates you know obviously stuff like that I haven't seen a lot of incompatibilities between like 7.2 and 7.3 that kind of thing you don't run into that a lot um as I said the entire Powershell distribution is in that one directory that's where like vs code looks by default um so if you put it somewhere else it'll work you just may have to do a little bit of work depending on the tooling um there's no hidden surprises because that's what I I have a post up on my site about shoving it into an application bundle cause I was just kind of curious because I realized okay so this would be cool if it's a simple enough install I could just in theory if I wanted to use Powershell inside an Apple app right I could just do this because then maybe I could I could build the UI and then pass the UI field choices to Powershell as parameters right that'd be kind of cool and so I just shoved the whole folder up in there and I you if you look at the post obviously I was not doing anything hugely complicated but it did allow me to reference Powershell and I didn't have to do any I mean but you do have to tell it where Powershell is right but other than that it's no different than if you shove a helper app into resources it's the same concept that's that's literally what you're doing is you're treating Powershell as a helper app um well I'm not a lawyer and I've never tried I am absolutely sure there is no way you're going to get an entire Powershell runtime distribution into the App Store um I'm going to go out on a limb like I mean I'm going to stand about here instead of here and say I don't think that'll get approved but internally or without using the the App Store you should be fine uh FYI I looked on GitHub and Powershell is currently MIT licensed so okay free to do whatever you want yes I keep forgetting to look at that yeah MIT licenses is you know if if the BSD license is too complicated MIT is a good way to go so yeah it's it's they're they're very cool about that and I think this is one where where it catches people have gone about Microsoft they've got like they're they're weird kind of we want to do open source we're not sure what to do with them but you do have some groups Powershell among them I think.net may be the same way where they're just like we want you to use this because ultimately the more people who use Powershell this benefits us long term it's a long game long tail so they're just throwing it out there you want to use it you can um I would imagine that if someone it's possible to write a Powershell bridge for Mac OS the same way you have like applescript Objective C which is the Apple script Bridge you could absolutely do that I'm not I'm not that good but if someone did that that I think would be kind of a cool thing it would probably I know the Powershell team would probably want to throw money at you to go work for them um because I talked to them about and they said we'd love to but there's not enough demand we would absolutely do that if there was the demand yes you were using uh uh applescript as a presentation layer yes um have you had any opportunity to play around with possibly using uh Coco dialogue instead no I mean I mean I think you could use anything basically why because you can use you can command line your way through display dialogue and things like that if you can command line your way through Coco dialogue I've never used it but if there's a command line hooks into what it's showing on the screen and it can pass back those parameters in a coherent way yeah you absolutely could you could use almost any kind of UI tool it's all about how you call it and what it sends back and if it's sending back anything vaguely stringish array string-ish it should work fine so this isn't so much of a question as a statement but if anyone's really new to Powershell and they're like really excited because they want to pull things over there is a difference between Powershell and Powershell core yes you find a script from five years ago that looks really cool that doesn't have any Windows components you think is you start banging your head on the wall there is some significant syntax differences there yeah um and like I said especially anything with the letters wmi or cim assume it will not work because those are rely on very specific Windows features to work you can get the same results but you're not going to do it with the same statement um yeah there are and and sometimes it's just a matter one thing that I think if you look in the Powershell documentation Microsoft is actually pretty good about saying which versions this works on so it'd be like Windows only that kind of thing it's not it's not real obvious sometimes and I don't think they're 100 consistent on them but they're pretty good about this does not work on anything but Windows this is Windows only this is and if you're looking in Powershell Gallery you can actually one of the first filters you can do is operating system so it's like Mac OS and you watch the thousands go to you know 800. but it's a good 800 so you know quality over quantity um hey I do a lot of um like batch operations using like get it get ad user get ad user group on a PC any workarounds with doing that with Powershell on the Mac you know even though the max obviously not bound to ad for the for most of us I mean you what you're using for a lot of that is the Unix utilities to get you that and so you just run the command via invoke command start process that kind of thing and you get the results back and then you Powershell it so and that's but the nice thing is that you don't have to do anything special there's no like special shell command you just run the shell command also if you want to call Powershell from the shell environment or from Apple script the command is pwsh so you can you can run it both ways you can hand it parameters which I've done and let the Powershell or you can run entire Powershell scripts you can you can let it do what it's good at if you want to and then have that spit its results back out to a bash script to applescript um anyone using jxa it'll work there too so it's it's definitely a two-way street on that in terms of that kind of integration uh uh okay 18 minutes early cool um thank you everyone so much for showing up I do appreciate it um and again if there's anybody got questions later I am easily reachable I think they've got all my email stuff on the on the website so thank you so much there's some reasons foreign
Info
Channel: MacAdmins Conference
Views: 1,718
Rating: undefined out of 5
Keywords:
Id: 7_8VePOngxQ
Channel Id: undefined
Length: 55min 9sec (3309 seconds)
Published: Tue Aug 01 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.