Latest / CyberSecurity Summary / PowerShell for Sysadmins: Workflow Automation Made Easy
Transcript
- 0:00Speaker 1: Welcome to the deep dive. Looks like we're diving into
- 0:02Speaker 1: the world of PowerShell today. Yeah, you want to learn
- 0:05Speaker 1: how to use it to automate all those tedious tasks
- 0:08Speaker 1: you have to do in Windows. And we've got some
- 0:11Speaker 1: great resources to guide us.
- 0:12Speaker 2: Yeah.
- 0:13Speaker 1: Absolutely, We've got excerpts from PowerShell for Sissedminds by Adam
- 0:17Speaker 1: Bertram and some intriguing info from the No Starch Press catalog.
- 0:22Speaker 2: Nice.
- 0:23Speaker 1: So, are you ready to unlock the power of PowerShell
- 0:27Speaker 1: and boost your efficiency?
- 0:29Speaker 2: Absolutely, let's dive in. PowerShell is really a game changer. Okay.
- 0:33Speaker 2: Imagine controlling your systems with code, automating all those boring,
- 0:38Speaker 2: repetitive tasks, and even managing renote computers. Oh wow, all
- 0:42Speaker 2: from one central place.
- 0:44Speaker 1: That sounds amazing, especially for someone like me, always looking
- 0:48Speaker 1: for ways to be more efficient and to save a
- 0:50Speaker 1: little bit of time. Of course, now, one thing that
- 0:52Speaker 1: really caught my eye in the book was that PowerShell
- 0:55Speaker 1: was designed to be user friendly, absolutely, even for people
- 0:58Speaker 1: who aren't you know, hardcore programmers.
- 1:01Speaker 2: It was built for sissigments from the ground up.
- 1:04Speaker 1: And is that because of features like tab completion. I
- 1:07Speaker 1: saw that mention in there, tab.
- 1:08Speaker 2: Completion is a life saver.
- 1:10Speaker 1: Okay.
- 1:10Speaker 2: Instead of memorizing every single command in every parameter, you
- 1:15Speaker 2: can just type part of it, okay, and powershow will
- 1:19Speaker 2: try to predict what you need. Oh nice, especially when
- 1:21Speaker 2: you're working with longer commands or more complex scripts later on.
- 1:25Speaker 1: Yeah, that's going to come in handy definitely. Okay. So
- 1:28Speaker 1: tab completion, Yeah, definitely makes it less intimidating. Sure, so
- 1:31Speaker 1: that's great. Now. Another thing I kept seeing was that
- 1:34Speaker 1: in PowerShell everything is an object.
- 1:37Speaker 2: Everything's an object?
- 1:38Speaker 1: What does that even mean?
- 1:40Speaker 2: It's a little bit of a mind shift, but once
- 1:42Speaker 2: you grasp that concept, it really unlocks the logic of PowerShell. Okay,
- 1:48Speaker 2: think of it this way. Even a simple string of text, Yeah,
- 1:52Speaker 2: like the word blue, that's not just text in Power Show.
- 1:55Speaker 2: It's a string object.
- 1:56Speaker 1: So it's more than just the letters b lue exactly.
- 2:00Speaker 2: It has properties like its length, which tells you how
- 2:03Speaker 2: many characters are in the string, and it also has methods,
- 2:08Speaker 2: which are basically actions that you can perform on that strength.
- 2:12Speaker 1: So, for example, could I use a method to change
- 2:16Speaker 1: that string to all upper case?
- 2:18Speaker 2: You absolutely could? Okay, there's a method called two upper Okay, Specifically,
- 2:23Speaker 2: for that.
- 2:23Speaker 1: That makes sense. Yeah, but how would I know what
- 2:27Speaker 1: properties and methods?
- 2:28Speaker 2: That's where your new best friend comes in. Okay, get
- 2:31Speaker 2: member member. You can use this command on any object
- 2:34Speaker 2: to see all of its properties in methods.
- 2:36Speaker 1: Get members like it's like an X ray for a
- 2:39Speaker 1: PowerShell object. I like that. Get member goes in the
- 2:42Speaker 1: toolbox absolutely. Now. The book also talks about A rays. Yes,
- 2:46Speaker 1: and A ray lists are those related to this whole
- 2:50Speaker 1: object's concept.
- 2:52Speaker 2: They are? Okay, so once you start working with more
- 2:54Speaker 2: than one object, you need a way to organize them, okay, right.
- 2:59Speaker 2: A rays are basically containers. They can hold a fixed
- 3:02Speaker 2: number of objects.
- 3:03Speaker 1: So if I have like a list of usernames, put
- 3:05Speaker 1: those in an array exactly.
- 3:07Speaker 2: Now. If you're dealing with much larger sets of data,
- 3:11Speaker 2: array lists are even better. They can grow dynamically, so
- 3:15Speaker 2: you don't have to preset the size.
- 3:18Speaker 1: Got it. So arrays for smaller fixed sets of data,
- 3:23Speaker 1: arraylists for larger dynamic data sets.
- 3:26Speaker 2: It's all about choosing the right tool for the job.
- 3:29Speaker 1: It is, right, Yeah, okay, cool, So far everything seems
- 3:32Speaker 1: pretty straightforward. But I know we're just scratching the surface here.
- 3:36Speaker 1: Oh yeah, what's next?
- 3:37Speaker 2: On the agenda, let's talk about scripting. Okay, this is
- 3:41Speaker 2: where you can really start automating more complex tasks. But
- 3:45Speaker 2: before we get into that, yeah, we need to talk
- 3:47Speaker 2: about something called execution policies.
- 3:49Speaker 1: Execution policies, Yes, what are those all about?
- 3:52Speaker 2: They're all about security.
- 3:53Speaker 1: Okay.
- 3:54Speaker 2: So execution policies control what kind of PowerShell scripts can
- 3:59Speaker 2: actually be run on your system. There are different levels
- 4:03Speaker 2: of restriction, so some policies might prevent you from running
- 4:07Speaker 2: scripts downloaded from the internet.
- 4:08Speaker 1: Right for security reasons exactly.
- 4:10Speaker 2: There's a policy called restricted which does exactly that, and
- 4:14Speaker 2: that's actually the default on many systems, just to prevent
- 4:18Speaker 2: you know, yeah, accidentally running something that could be harmful.
- 4:23Speaker 1: Makes sense.
- 4:24Speaker 2: Now there are other policies.
- 4:25Speaker 1: Too, Okay, what are those.
- 4:27Speaker 2: All Signed only allows you to run scripts if they've
- 4:32Speaker 2: been digitally signed by a trusted source, got it and
- 4:36Speaker 2: remote signed, unless you run your own scripts and any
- 4:40Speaker 2: sigence scripts you download.
- 4:41Speaker 1: Okay, So that's kind of a balance between security and
- 4:45Speaker 1: flexibility exactly. So it sounds like I need to understand
- 4:48Speaker 1: these execution policies you do to make sure I can
- 4:51Speaker 1: run the scripts that I want to run, exactly. Okay,
- 4:55Speaker 1: and then to actually help me write and manage those scripts. Yes,
- 5:00Speaker 1: book introduces the PowerShell.
- 5:02Speaker 2: I yes, the PowerShell is.
- 5:04Speaker 1: What does I stand for?
- 5:05Speaker 2: It stands for Integrated Scripting Environment, basically a code editor
- 5:10Speaker 2: designed specifically for PowerShell. It has features like syntax highlighting
- 5:15Speaker 2: okay to help you write error free code, and debugging
- 5:21Speaker 2: tools to help you troubleshoot your scripts when things.
- 5:24Speaker 1: Go wrong, which they inevitably will of course, So this
- 5:28Speaker 1: sounds like this will be really helpful.
- 5:30Speaker 2: It'll help you a lot.
- 5:31Speaker 1: Once I start getting into more complex scripting.
- 5:33Speaker 2: Absolutely.
- 5:34Speaker 1: Okay. So we've covered the console, I've talked about objects,
- 5:37Speaker 1: We've even touched on security a bit, a little bit.
- 5:40Speaker 1: Now I'm ready to dive into the scripting thing.
- 5:42Speaker 2: Scripting is where the real magic happens. And the best
- 5:45Speaker 2: part is PowerShell was built on this principle of don't
- 5:50Speaker 2: repeat yourself. Okay, So it's all about automation.
- 5:53Speaker 1: I love that. I love that principle. So what are
- 5:57Speaker 1: some of the key concepts I need to know to
- 6:00Speaker 1: start writing these effective PowerShell scripts?
- 6:04Speaker 2: Control flow statements, control flow states. These are your building blocks, Okay.
- 6:08Speaker 2: They allow you to create scripts that make decisions okay,
- 6:11Speaker 2: and adapt to different situations.
- 6:13Speaker 1: So it's like a choose your own adventure.
- 6:15Speaker 2: It's like to choose your own adventures for your computer.
- 6:17Speaker 1: Okay, I'm intrigued. Yeah, tell me more about these control
- 6:21Speaker 1: flow statements. What does they look like?
- 6:23Speaker 2: Well, you have flightful statements okay, which lets you perform
- 6:28Speaker 2: different actions based on certain conditions. So, for example, imagine
- 6:33Speaker 2: you want to write a script that checks the free
- 6:36Speaker 2: space on your hard drive. Okay, you could use an
- 6:39Speaker 2: if statement to check if the free space is below
- 6:42Speaker 2: a certain threshold, right, and then send you an alert
- 6:45Speaker 2: if it is.
- 6:46Speaker 1: Oh, that's useful. Yeah, I can already see how that
- 6:49Speaker 1: would be.
- 6:49Speaker 2: Helpful practical example. Yeah. Yeah.
- 6:52Speaker 1: What other kinds of control flow statements are there?
- 6:56Speaker 2: They're also switch statements, okay, which can be more efficient
- 7:01Speaker 2: than a bunch of IF statements if you're checking against
- 7:04Speaker 2: multiple possible values.
- 7:06Speaker 1: So if statements for simple conditions, which statements for multiple conditions?
- 7:10Speaker 2: Exactly?
- 7:11Speaker 3: Got it?
- 7:12Speaker 1: What about repeating actions, like if I wanted to perform
- 7:16Speaker 1: the same task but on multiple files.
- 7:20Speaker 2: That's where loops come in.
- 7:21Speaker 1: Okay.
- 7:22Speaker 2: PowerShell has several types of loops, like for each wile.
- 7:27Speaker 2: Each loop has its own unique way of repeating actions
- 7:32Speaker 2: based on certain conditions.
- 7:34Speaker 1: So with loops, I could write a script that would
- 7:38Speaker 1: go through every file and a folder and perform some action.
- 7:42Speaker 2: On each one exactly. You could rename them, move them.
- 7:47Speaker 1: Or whatever I want, compress them, got.
- 7:48Speaker 2: It, whatever you can imagine.
- 7:51Speaker 1: This is starting to feel powerful, it is. Okay, So
- 7:55Speaker 1: we've got these conditional statements like if and switch, we've
- 7:58Speaker 1: got loops for repeating actions. Absolutely anything else I need
- 8:02Speaker 1: to know about control flow.
- 8:03Speaker 2: One more crucial thing, okay, error handling.
- 8:07Speaker 1: Error handling.
- 8:08Speaker 2: What happens when something unexpected happens in your script?
- 8:11Speaker 3: Oh?
- 8:11Speaker 1: Yeah, of course things are going to go wrong.
- 8:14Speaker 2: PowerShell has ways to handle those situations gracefully. Okay, so
- 8:18Speaker 2: your script doesn't just crash and burn.
- 8:20Speaker 1: Okay, good error handling. I can see why that.
- 8:23Speaker 2: Would be important, especially if your scripts are running critical tasks.
- 8:26Speaker 2: You don't want them to just fall apart. So PowerShell
- 8:30Speaker 2: uses these things called exceptions and errors to deal with
- 8:33Speaker 2: these unexpected situations, and learning how to anticipate and manage
- 8:38Speaker 2: those errors is really key. Got it to writing robust
- 8:44Speaker 2: and reliable scripts.
- 8:45Speaker 1: So control flow statements, loops, and error handling error handling.
- 8:50Speaker 1: Those are the foundation.
- 8:51Speaker 2: Those are your foundations for scripting.
- 8:53Speaker 3: Got it.
- 8:54Speaker 2: Yeah.
- 8:54Speaker 1: Once I understand those, I'm well on my way.
- 8:57Speaker 2: You're well on your way to.
- 8:59Speaker 1: Writing some seriously powerful scripts.
- 9:01Speaker 2: Absolutely.
- 9:02Speaker 1: I can't wait to start putting this all into practice.
- 9:05Speaker 1: Is there anything else we should cover before we move on?
- 9:08Speaker 1: One more thing to some real world examples.
- 9:10Speaker 2: Let's talk about functions and modules.
- 9:13Speaker 1: Functions and modules.
- 9:14Speaker 2: This is a building blocks for organizing and reusing your
- 9:18Speaker 2: PowerShell code. Okay, think of them like pre build components
- 9:23Speaker 2: that you can assemble to create more complex scripts.
- 9:26Speaker 1: Sounds intriguing. Tell me more about functions and modules.
- 9:30Speaker 2: So functions are like mini programs okay, within your script.
- 9:34Speaker 2: They let you group together reusable blocks of code, which
- 9:38Speaker 2: makes your scripts more organized, more readable, and easier to test.
- 9:43Speaker 2: Got it, and to keep things clear? Yeah. The book
- 9:46Speaker 2: really emphasizes giving your functions descriptive names, using what's called
- 9:51Speaker 2: the verb noun convention.
- 9:53Speaker 1: Verb noun convention. Yes, what is that?
- 9:55Speaker 2: It's a simple way to name your functions so that
- 9:57Speaker 2: they clearly describe what they do. Sample. Instead of naming
- 10:01Speaker 2: a function like processed data, you might have a function
- 10:05Speaker 2: called get user data or set file permissions.
- 10:09Speaker 1: Okay, so the verb comes first.
- 10:10Speaker 2: Verb first, and then the noun and then the noun.
- 10:13Speaker 1: That makes perfect sense.
- 10:14Speaker 2: It makes it much easier to understand what the function
- 10:17Speaker 2: does exactly just by looking at its name.
- 10:19Speaker 1: Yeah, descriptive names are always good, absolutely. So what about module?
- 10:23Speaker 2: Modules are basically containers for your functions. They let you
- 10:28Speaker 2: bundle a bunch of related functions together so you can
- 10:31Speaker 2: share them and reuse them easily. Imagine you have a
- 10:35Speaker 2: set of functions for managing user accounts. You can put
- 10:39Speaker 2: all those functions together in a module called user Management.
- 10:44Speaker 1: So it's like a library.
- 10:45Speaker 2: It's like a library, a reusable PowerShell code.
- 10:48Speaker 1: Okay, Yeah, that's a brilliant way to organize things. It is,
- 10:52Speaker 1: and not have to reinvent the wheel every time you
- 10:55Speaker 1: need to do a common task.
- 10:57Speaker 2: Don't repeat yourself, right exactly. And you can even share
- 11:01Speaker 2: your modules with others. Oh wow, download modules and other
- 11:04Speaker 2: people have.
- 11:05Speaker 1: Created so it's like having access, yeah to this vast collection.
- 11:10Speaker 2: It's like a giant tool box.
- 11:11Speaker 1: Yeah, of pre built, pre built powershow tools, powersholl tool
- 11:15Speaker 1: This is getting better and better. It is now. I'm
- 11:18Speaker 1: really excited to see how all of this comes together
- 11:21Speaker 1: in a real world scenario. All right, where do we
- 11:24Speaker 1: go from here?
- 11:25Speaker 2: Since you're interested in managing computers remotely, okay, let's talk
- 11:28Speaker 2: about powershow remoting power Shell remoting. It's like having a
- 11:32Speaker 2: virtual control panel that lets you manage computers anywhere on
- 11:36Speaker 2: your network.
- 11:37Speaker 1: PowerShell remoting. Yeah, that sounds incredibly powerful.
- 11:41Speaker 2: It is.
- 11:42Speaker 1: Tell me more about how it works.
- 11:44Speaker 2: Imagine you need to install software, okay on one hundred computers.
- 11:49Speaker 2: Instead of manually logging into each one, Yeah, no, thanks,
- 11:52Speaker 2: you could use PowerShell remoting okay to send commands to
- 11:56Speaker 2: all of them simultaneously.
- 11:57Speaker 1: Oh wow, that would be a huge time saver.
- 12:00Speaker 2: It would be.
- 12:00Speaker 1: Ok what are some of the key things I need
- 12:02Speaker 1: to know?
- 12:04Speaker 2: So the book mentions this command, Yeah, called invoke command.
- 12:08Speaker 2: Invoke command, and that's your go to tool for running
- 12:11Speaker 2: commands on remote computers. It's great for quick tasks, but
- 12:16Speaker 2: for more complex scenarios, you might want to use something
- 12:19Speaker 2: called sessions.
- 12:21Speaker 1: Sessions, Yes, what are those?
- 12:23Speaker 2: So? A session is basically a persistent connection to a
- 12:28Speaker 2: remote computer. It lets you maintain that connection and execute
- 12:33Speaker 2: multiple commands without having to constantly re establish that communication.
- 12:38Speaker 1: Got it? Yeah, So invoke command for quick tasks, sessions
- 12:42Speaker 1: for more involved involve man management. Yeah, okay, Now I'm
- 12:46Speaker 1: really curious to see how this PowerShell remoting works in practice.
- 12:53Speaker 1: Do we have any real world examples to look at?
- 12:56Speaker 2: The book has this really cool example of creating a inventory.
- 13:00Speaker 1: Script server inventory script. What would that do?
- 13:03Speaker 2: So imagine you need to gather information about all the
- 13:06Speaker 2: servers on your network, things like their operating system versions,
- 13:10Speaker 2: their hardware specs, what software is installed on them. A
- 13:14Speaker 2: server inventory script can automate that whole process for you.
- 13:18Speaker 1: That sounds incredibly useful. It is, especially if you're managing
- 13:22Speaker 1: a large network.
- 13:23Speaker 2: If you have a lot of servers.
- 13:24Speaker 1: So how does PowerShell actually gather all that information?
- 13:28Speaker 2: The book focuses on using two main techniques okay, querying
- 13:33Speaker 2: active directory okay, and using these things called CIMWM I
- 13:38Speaker 2: cmdalitz Okay.
- 13:39Speaker 1: Active directory, I'm familiar with it.
- 13:41Speaker 2: Okay.
- 13:42Speaker 1: That's basically a directory of all the users.
- 13:45Speaker 2: It's like a phone book and computer, yeah, for your
- 13:47Speaker 2: network and the network right, Okay, it's a gold mine
- 13:50Speaker 2: of information okay for CIS edmins.
- 13:52Speaker 1: So we can query active directory to find out everything
- 13:56Speaker 1: we need to know about our server.
- 13:57Speaker 2: You can't their names, their I P addresses, they're operating systems,
- 14:03Speaker 2: domain memberships, and much more.
- 14:06Speaker 1: Active directory makes sense. But these cimw MI cmdalits.
- 14:10Speaker 2: Those sound a little bit more mysterious.
- 14:12Speaker 1: They're a little bit more low level, okay, but incredibly powerful.
- 14:17Speaker 1: Think of cimwm I as a way to talk directly
- 14:22Speaker 1: to the hardware and software components of your Windows systems.
- 14:27Speaker 1: They give you access to a ton of information that
- 14:31Speaker 1: you can't get through active directory.
- 14:32Speaker 2: The active directory is kind of like the high level
- 14:35Speaker 2: overview of the network.
- 14:36Speaker 1: The big picture.
- 14:37Speaker 2: And then CIWMI. Yeah, lets us drill down, drill down
- 14:43Speaker 2: into the nitty gritty detail exact of each server.
- 14:46Speaker 1: By combining those two techniques, you can gather a truly
- 14:50Speaker 1: comprehensive inventory of your server environment.
- 14:54Speaker 2: And the book even mentions, yes, generating reports from this data.
- 14:58Speaker 1: Reports are essential.
- 14:59Speaker 2: Okay, Yeah, I can see how that would be helpful
- 15:02Speaker 2: to visualize and analyze all that information.
- 15:04Speaker 1: It makes the data actionable, right Yeah, Okay, So this
- 15:08Speaker 1: server inventory script sounds like a great example. It is
- 15:11Speaker 1: how PowerShell can automate. It shows you this complex, real
- 15:16Speaker 1: world task.
- 15:17Speaker 2: It's a great practical example.
- 15:18Speaker 1: Cool, and there's even more real world projects. Oh, Yeah,
- 15:22Speaker 1: covered in this book.
- 15:23Speaker 2: The book is packed with them.
- 15:24Speaker 1: You also learn about automating user account creation, yes, deploying
- 15:29Speaker 1: web servers, working with cloud platforms like Azure and Aws.
- 15:34Speaker 2: All those things.
- 15:35Speaker 1: Wow, it sounds like we have a lot of exciting
- 15:37Speaker 1: material to make.
- 15:38Speaker 2: We have a lot to talk about.
- 15:39Speaker 1: This deep dive is really opening my eyes to the possibilities.
- 15:43Speaker 2: A powerful tool.
- 15:44Speaker 1: Yes, of PowerShell. What should we explore.
- 15:47Speaker 2: Next before we move on to more advanced projects?
- 15:50Speaker 1: Okay?
- 15:50Speaker 2: I think it would be helpful to get you comfortable
- 15:53Speaker 2: with the PowerShell console itself. Okay, so why don't we
- 15:57Speaker 2: try out a few basic commands?
- 15:59Speaker 1: All right, let's do it and.
- 16:00Speaker 2: See how it all works in practice.
- 16:01Speaker 1: I'm ready to get my hands dirty.
- 16:03Speaker 2: Okay, great, let's start with a cam dill it okay,
- 16:05Speaker 2: called get command.
- 16:07Speaker 1: Get command.
- 16:08Speaker 2: This is a great way to see all the available
- 16:10Speaker 2: commands and power show. So go ahead and type get
- 16:12Speaker 2: command in the console and press enter.
- 16:15Speaker 1: Okay, I see a long list of commands scrolling by.
- 16:18Speaker 2: There are a lot.
- 16:19Speaker 1: Wow, it looks like PowerShell has commands for just about everything.
- 16:22Speaker 2: It's a very versatile tool, it is. Yeah. Okay, now
- 16:25Speaker 2: let's try command. You might be familiar with from the
- 16:28Speaker 2: doss days. Type deer and press enter.
- 16:33Speaker 1: Okay, I see a listing of the files and folders
- 16:35Speaker 1: in my current directory. It looks just like the output
- 16:38Speaker 1: from the old deer command is Is that just a coincidence?
- 16:41Speaker 2: Not at all?
- 16:42Speaker 1: Okay?
- 16:42Speaker 2: So PowerShell has this feature called aliases okay, which are
- 16:46Speaker 2: basically nicknames for common commands. So deer is actually an
- 16:50Speaker 2: alias for the get child items CM dillit okay, which
- 16:55Speaker 2: is the PowerShell way to list files and folders.
- 16:58Speaker 1: So they kept some of the familiar man. Yeah, they
- 17:01Speaker 1: try to make it from other command line environments easy
- 17:03Speaker 1: to learn, to make it easier.
- 17:04Speaker 2: To people coming from different backgrounds, right, exactly. Now let's
- 17:08Speaker 2: try something a little more PowerShell specific.
- 17:11Speaker 1: Okay.
- 17:12Speaker 2: Remember the get member CM in tullet.
- 17:15Speaker 1: Get member we talked about earlier, the one that lets.
- 17:17Speaker 2: Us see the properties and.
- 17:19Speaker 1: Methods all the properties and methods of an object of
- 17:21Speaker 1: an object exactly?
- 17:22Speaker 2: Yes, I remember that one.
- 17:23Speaker 1: Okay. So let's create a simple string object like the
- 17:27Speaker 1: one we discussed before. Type this color equals blue color
- 17:31Speaker 1: equals blue, Press enter okay. Done.
- 17:33Speaker 2: Now let's use get member to see what's inside this
- 17:37Speaker 2: color object. Okay, type of color okay, pipe, okay, get member,
- 17:42Speaker 2: get member and press enter. Okay, now you should see.
- 17:46Speaker 1: Wow, this is amazing. Yeah, I see a whole list
- 17:49Speaker 1: of properties and methods. All those properties and methods, there's
- 17:52Speaker 1: the length property we talked aboutre it is and methods
- 17:55Speaker 1: like to upper and to a lower He got it.
- 17:58Speaker 1: So if I wanted to convert that string to all uppercase, yes,
- 18:01Speaker 1: I could just type your copyer two up exactly.
- 18:04Speaker 2: And if you want to converted to lowercase color to
- 18:07Speaker 2: lower Okay.
- 18:08Speaker 1: This object oriented approach is really starting to click for me.
- 18:13Speaker 2: It's a powerful concept.
- 18:15Speaker 1: It is. It's like each object has its own set
- 18:19Speaker 1: of tools and capability.
- 18:20Speaker 2: And that's one of the key things that makes PowerShell
- 18:24Speaker 2: so powerful, flexible.
- 18:27Speaker 1: This is really exciting, it is I'm starting to see
- 18:29Speaker 1: the potential of PowerShell.
- 18:31Speaker 2: Yeah, and we've only just scratched the surface.
- 18:33Speaker 1: I know, right, Yeah, and we've only just scratched the surface.
- 18:35Speaker 2: We have a lot more to explore. Okay, but for now,
- 18:38Speaker 2: let's take a short break and when we come back,
- 18:41Speaker 2: we'll dive into more advanced PowerShell techniques and real world examples.
- 18:48Speaker 2: Sounds good, Welcome back, You're ready to keep exploring the
- 18:52Speaker 2: world of PowerShell.
- 18:53Speaker 1: Absolutely, I'm excited to see what else we can do
- 18:56Speaker 1: with it.
- 18:56Speaker 2: All right, so you also send some info about security.
- 19:01Speaker 1: Yes, I was thinking, you know, if I'm going to
- 19:04Speaker 1: be using this in a work setting, I can't imagine
- 19:07Speaker 1: just embedding passwords in plain texts within a script.
- 19:11Speaker 2: No, No, never do that, but especially.
- 19:13Speaker 1: If they're going to be used on production systems.
- 19:15Speaker 2: Yeah, you got to keep security in mind, especially with PowerShell.
- 19:19Speaker 1: So how do we actually secure those sensitive bits of information?
- 19:23Speaker 2: Well, the book talks about using encryption to protect that
- 19:26Speaker 2: kind of data.
- 19:27Speaker 1: So are there built in tools for that? In PowerShell?
- 19:29Speaker 2: There are PowerShell has sem dalits specifically designed for encryption.
- 19:34Speaker 1: All right, what are they?
- 19:35Speaker 2: So there's the sem dealt called get Credential Credential, which
- 19:38Speaker 2: lets you store a username and password securely in something
- 19:42Speaker 2: called a PCEX credential object.
- 19:44Speaker 1: A piece credential object.
- 19:46Speaker 2: And then you can encrypt that and save it to
- 19:48Speaker 2: a file.
- 19:49Speaker 1: So it's like having a secure.
- 19:50Speaker 2: Vault exactly, much better than plain.
- 19:53Speaker 1: Text, right, way better? Okay, So encryption is important, always
- 19:56Speaker 1: a good idea, especially when we're dealing with these automated scripts.
- 19:59Speaker 2: Especially in work environment.
- 20:00Speaker 1: Right. Yeah, Now I'm curious to see how we can
- 20:03Speaker 1: apply all this knowledge to some real world tasks.
- 20:07Speaker 2: Right.
- 20:07Speaker 1: The book talks about a server inventory script.
- 20:09Speaker 2: Yeah, those are incredibly useful.
- 20:11Speaker 1: Okay, So what would that do.
- 20:13Speaker 2: Imagine you've got dozens or even hundreds of servers, okay,
- 20:17Speaker 2: and you need to know what operating systems they're running,
- 20:21Speaker 2: what hardware they have, what software is installed. A server
- 20:26Speaker 2: inventory script can automate all of that.
- 20:28Speaker 1: That sounds amazing, it really is. But how does PowerShell
- 20:32Speaker 1: actually gather all that information?
- 20:34Speaker 2: So the book uses two main techniques, okay, querying active
- 20:39Speaker 2: directory and using those cimwmcmdalits.
- 20:43Speaker 1: Yeah, IMWMRO we talked about earlier.
- 20:45Speaker 2: So active directory. Yeah, it's basically like a phone book
- 20:49Speaker 2: for the network.
- 20:50Speaker 1: That's a good way to think about it.
- 20:51Speaker 2: Okay.
- 20:52Speaker 1: It's a central directory of all the users and computers
- 20:55Speaker 1: on the network.
- 20:56Speaker 2: So active directory is like the high level view. It
- 20:59Speaker 2: gives you the big picture, okay, and then the CIMWM
- 21:03Speaker 2: I cmdal it's.
- 21:04Speaker 1: Those let you drill down, okay, into the specifics of
- 21:07Speaker 1: each machine.
- 21:08Speaker 2: So it's like active directory tells us you know the
- 21:10Speaker 2: server's name, it's IP address. Right, but then CIWM I
- 21:15Speaker 2: can tell us you know how much.
- 21:17Speaker 1: Ram it has, exactly what kind of hard drive, all
- 21:20Speaker 1: the details, got it.
- 21:21Speaker 3: Yeah.
- 21:22Speaker 1: So by combining these two techniques, yeah, you can get
- 21:24Speaker 1: a really comprehensive inventory.
- 21:27Speaker 2: And the book even mentions generating reports from this data.
- 21:32Speaker 1: Reports are essential for making that data useful. Yeah, because
- 21:36Speaker 1: otherwise it's just it's just a jumble of information. Right,
- 21:39Speaker 1: exact report can summarize it, present it in a way
- 21:42Speaker 1: that's easy to understand.
- 21:44Speaker 2: Okay, so you can spot trends, identify issues, so on.
- 21:49Speaker 1: So this server inventory script is a great example of
- 21:52Speaker 1: how PowerShell.
- 21:54Speaker 2: Can automate it is it's a really practical example.
- 21:57Speaker 1: Yeah, these complex real world tasks they had a lot
- 22:00Speaker 1: of sisiments have to do on a regular basis. So
- 22:03Speaker 1: what other real world projects?
- 22:05Speaker 2: Wowbow, does the book go into automating user account creation?
- 22:10Speaker 1: Oh, tell me about it. Yeah, creating user accounts one
- 22:13Speaker 1: by one. It's tedious, setting passwords, assigning group memberships.
- 22:19Speaker 2: Yeah, it's a real time sink.
- 22:21Speaker 1: I can see how automating that would be a huge win.
- 22:23Speaker 2: It would free up so much of your time. So
- 22:26Speaker 2: the book actually has a script that does just that.
- 22:28Speaker 2: It can generate user names based on first and last names,
- 22:32Speaker 2: set random passwords NIC and force password change so that
- 22:35Speaker 2: that's good at first, logan.
- 22:37Speaker 1: Right for security reasons exactly, okay.
- 22:40Speaker 2: And even assign those departmental attributes and employee numbers.
- 22:44Speaker 1: So it's like having a personal assistant.
- 22:46Speaker 2: It's like having a little helper that takes care of
- 22:48Speaker 2: all that tedious work.
- 22:49Speaker 1: And the best part is what's that we can customize it.
- 22:52Speaker 1: You can absolutely customize it to fit our organization's specific.
- 22:56Speaker 2: Requirements and fit your exact needs.
- 22:58Speaker 1: Okay, So user account creation another task automated, another one.
- 23:02Speaker 2: Off the list. What else, have a deploying web servers
- 23:05Speaker 2: with ice?
- 23:06Speaker 1: Deploying web servers with ICE?
- 23:09Speaker 2: PowerShell can automate that whole process too.
- 23:11Speaker 1: Wow, So it's not just for managing Windows systems.
- 23:14Speaker 2: No, PowerShell can do a lot more than that. It
- 23:16Speaker 2: can even handle web server stuff.
- 23:18Speaker 1: So what kind of tasks can we automate with PowerShell?
- 23:21Speaker 1: In that context?
- 23:22Speaker 2: You can create websites, configure bindings bindings, set up app
- 23:27Speaker 2: pools at pools, and even configure SSL certificates.
- 23:32Speaker 1: Hold on bindings at pools, SSL certificates.
- 23:35Speaker 2: Yeah, it's a whole new world can.
- 23:37Speaker 1: You break those down for me. I'm not super familiar
- 23:39Speaker 1: with all the web server jargon.
- 23:41Speaker 2: So bindings basically determine how clients connect to your website.
- 23:47Speaker 2: They specify the IP address right, the port, and the
- 23:50Speaker 2: host name at Pools are like containers that isolate different
- 23:54Speaker 2: websites and applications running on your server.
- 23:57Speaker 1: Okay.
- 23:58Speaker 2: And SSL certificates, yeah, provide encryption and security for your
- 24:03Speaker 2: website's traffic.
- 24:05Speaker 1: Okay. So basically PowerShell gives us granular control.
- 24:08Speaker 2: It gives you complete control over all.
- 24:10Speaker 1: Those aspects of a web server. That's just starting to
- 24:13Speaker 1: feel like we're building a whole it infrastructure with code.
- 24:17Speaker 2: It's like you're an architect, but instead of bricks and mortar,
- 24:20Speaker 2: you're using PowerShell commands.
- 24:22Speaker 1: What else can PowerShell do in terms of managing servers
- 24:26Speaker 1: and applications.
- 24:27Speaker 2: Well, we can't forget about the cloud.
- 24:29Speaker 1: The cloud, oh right, Yeah.
- 24:30Speaker 2: The book actually dedicates a whole section to working with
- 24:33Speaker 2: cloud platforms like Azure and AWS.
- 24:36Speaker 1: So PowerShell is not just limited to on premises stuff.
- 24:40Speaker 2: It can reach out to the cloud as well.
- 24:42Speaker 1: Okay, what are some of the things we can do?
- 24:44Speaker 3: You can create virtual machines with PowerShell in the cloud
- 24:48Speaker 3: in Azure or AWS, manage storage accounts, deploy applications, okay,
- 24:55Speaker 3: even orchestrate complex cloud workflows.
- 24:59Speaker 2: Wow, power show.
- 25:00Speaker 1: It sounds like PowerShell's becoming like the universal language. It's
- 25:03Speaker 1: becoming very popular of it automation, especially as more and
- 25:06Speaker 1: more organizations move to the cloud. Right, yeah, okay, cloud
- 25:10Speaker 1: automation check. Check what other superpowers?
- 25:13Speaker 2: How about building your own PowerShell modules?
- 25:16Speaker 1: Does PowerShell have in store for us? That's right, building
- 25:19Speaker 1: our own modules.
- 25:19Speaker 2: So once you're comfortable with PowerShell, you can start packaging
- 25:23Speaker 2: your own scripts okay and functions into reusable modules.
- 25:28Speaker 1: So we could create our own custom.
- 25:29Speaker 2: Yeah, your own custom tools, PowerShell tools tailored to your
- 25:32Speaker 2: specific needs.
- 25:33Speaker 1: That's really cool.
- 25:35Speaker 2: It's a great way to level up your PowerShell skills
- 25:38Speaker 2: right right.
- 25:39Speaker 1: This deep dive is taking us on quite a.
- 25:41Speaker 3: Journey, it is.
- 25:42Speaker 2: We've covered a lot of ground.
- 25:43Speaker 1: We've gone from basic commands to cloud automation.
- 25:48Speaker 2: And now module development and module development.
- 25:50Speaker 1: Yeah, what's next?
- 25:52Speaker 2: Last time we talked about this project called power lab.
- 25:55Speaker 1: Power Lab remember that, Yes.
- 25:58Speaker 2: For building a whole lab environment from scratch, from scratch
- 26:02Speaker 2: using PowerShell.
- 26:03Speaker 1: I'm dying to know more about that.
- 26:04Speaker 2: That's a really fun project.
- 26:06Speaker 1: Welcome back to our deep dive into PowerShell. Last time
- 26:09Speaker 1: we were talking about this power lab project.
- 26:11Speaker 2: Yeah, power lab that lets us.
- 26:13Speaker 1: Build a whole lab environment from scratch using code. It's
- 26:18Speaker 1: a pretty amazing project, it is, and I'm really curious
- 26:21Speaker 1: to hear more about it.
- 26:22Speaker 2: Okay, Well, power Lab is a great example of how
- 26:25Speaker 2: powerful PowerShell can be.
- 26:26Speaker 1: Okay.
- 26:27Speaker 2: Imagine you can set up an entire virtual network, okay,
- 26:31Speaker 2: with servers, active directory and everything you need for testing
- 26:35Speaker 2: and development.
- 26:36Speaker 1: So it's like, all with code, our own little IT playground.
- 26:39Speaker 2: Exactly, your own personal IT playground. I like that.
- 26:42Speaker 1: Yeah, okay, but where would you even begin with something
- 26:45Speaker 1: like that?
- 26:46Speaker 2: It can seem daunting. Yeah, but that's the beauty of
- 26:50Speaker 2: power Lab Okay. It's designed to be approachable okay and
- 26:53Speaker 2: modular Okay.
- 26:54Speaker 1: So it breaks down this complex task exactly into smaller,
- 26:58Speaker 1: more manageable steps.
- 27:00Speaker 2: Right. The book starts by mentioning something called the power
- 27:02Speaker 2: Lab installer.
- 27:03Speaker 1: The power Lab installer.
- 27:05Speaker 2: What do you think that this?
- 27:06Speaker 1: Well, if power Lab is like building a house, okay,
- 27:09Speaker 1: I'm guessing the installer is kind of like laying the foundation.
- 27:12Speaker 2: You got it? Okay, It preps your system.
- 27:15Speaker 1: So it gets everything ready.
- 27:16Speaker 2: It takes care of all the prerequisites okay, like enabling PowerShell,
- 27:20Speaker 2: remoting ok configuring firewall rules, setting up user accounts, even
- 27:25Speaker 2: installing any necessary Windows features.
- 27:28Speaker 1: So it handles all that tedious setup stuff.
- 27:30Speaker 2: It automates all of that for you. I like it,
- 27:32Speaker 2: so you can just dive right.
- 27:33Speaker 1: In, right into the fun part to.
- 27:35Speaker 2: Building your lab environment. Now, once the power lab installer
- 27:40Speaker 2: has done its thing, Yeah, what do you think happens next?
- 27:44Speaker 1: Well, now we've got to actually build the lab environment
- 27:46Speaker 1: right right, So that's where we start defining all the
- 27:49Speaker 1: functions exactly do all the work.
- 27:51Speaker 2: So, for example, you might have a function called new
- 27:54Speaker 2: power lab vm okay.
- 27:55Speaker 1: For creating a virtual machine.
- 27:57Speaker 2: Right, or a new power Lab VHD okay.
- 28:00Speaker 1: For creating a virtual hard disk.
- 28:02Speaker 2: Exactly, or install powerly operating.
- 28:04Speaker 1: Systems, install the operating steam.
- 28:06Speaker 2: Yeah you're getting it.
- 28:07Speaker 1: So we're basically creating this toolbox. It's like a toolbox
- 28:10Speaker 1: of a reusable component, so.
- 28:11Speaker 2: Of specialized tools, right that we can then use to
- 28:14Speaker 2: build whatever lab environment, to.
- 28:16Speaker 1: Build whatever we need you need. And this is where
- 28:19Speaker 1: that verb noun naming convention comes in handy right, absolutely,
- 28:22Speaker 1: to keep everything organized.
- 28:23Speaker 2: Especially in a big project like.
- 28:25Speaker 1: This, right with so many different functions.
- 28:27Speaker 2: Yeah, you want your code to be readable and easy
- 28:30Speaker 2: to understand.
- 28:31Speaker 1: Okay, So we've got the foundation laid, We've got our
- 28:34Speaker 1: toolbox ready.
- 28:35Speaker 2: Okay.
- 28:35Speaker 1: What are some of the key steps.
- 28:37Speaker 2: So one of the first things you'll want to do.
- 28:39Speaker 1: In actually building the lab environment is set up active
- 28:43Speaker 1: directory directory.
- 28:44Speaker 2: Right, that's the heart of any Windows network, right.
- 28:46Speaker 1: For managing users and permissions and all that exactly. So
- 28:49Speaker 1: do we have to manually set that up?
- 28:51Speaker 2: No? No, No, PowerShell can automate that too, okay. Yeah. Power
- 28:55Speaker 2: lab has functions all right, for creating a new forest okay,
- 28:59Speaker 2: defining organizational units, creating user accounts, even assigning group memberships,
- 29:04Speaker 2: all through code, all through PowerShell scripts.
- 29:06Speaker 1: It's like we're building an IT empire with code.
- 29:09Speaker 2: I like that an IT empire.
- 29:11Speaker 1: What about the other parts of the lab, like what
- 29:14Speaker 1: like the SQL server and the web server. Do those
- 29:16Speaker 1: get the same automated treatment?
- 29:18Speaker 2: Of course they do. Okay. Remember all those cmd lets,
- 29:22Speaker 2: Yeah we talked about for configuring websites and bindings and
- 29:26Speaker 2: SSL certificates.
- 29:27Speaker 1: It's all coming back to me now.
- 29:29Speaker 2: Our lab uses all of that deploying configure.
- 29:32Speaker 1: So we're taking all these individual building blocks and assembling
- 29:36Speaker 1: them into.
- 29:36Speaker 2: A complete system, into a.
- 29:37Speaker 1: Functional lab environment exactly. So by the end of this project,
- 29:41Speaker 1: we essentially have a fully functional lab.
- 29:43Speaker 2: You'll have a fully automated lab environment that we can
- 29:46Speaker 2: use for whatever we want, that you can use for testing, development,
- 29:50Speaker 2: whatever you can dream up.
- 29:51Speaker 1: That's incredible.
- 29:53Speaker 2: It is pretty cool.
- 29:54Speaker 1: And the book doesn't stop there, right.
- 29:56Speaker 2: Nope, it goes even further.
- 29:58Speaker 1: It talks about refactoring the code.
- 30:00Speaker 2: Yes, refactory, can you explain what that is? Sure? Think
- 30:03Speaker 2: of refactoring, okay, as kind of tidying up your code,
- 30:07Speaker 2: making it more efficient, more readable, easier to.
- 30:11Speaker 1: Maintain, without actually changing what it does.
- 30:13Speaker 2: Without changing its functionality.
- 30:14Speaker 1: So it's like cleaning up your workshop.
- 30:16Speaker 2: It's like organizing your tools.
- 30:17Speaker 1: After a big project exactly.
- 30:19Speaker 2: Okay. Yeah, So the book shows you how to identify
- 30:24Speaker 2: common patterns in the code and extract them into more
- 30:27Speaker 2: generic functions.
- 30:28Speaker 1: So we're creating even more reusable building blocks.
- 30:31Speaker 2: You got it. We can save you even more time
- 30:34Speaker 2: in the future.
- 30:35Speaker 1: This whole deep dive, it's it's been an incredible journey
- 30:38Speaker 1: we've covered with that We've gone from basic commands basic
- 30:41Speaker 1: commands to cloud automation, coltivation, to module developed, module development, refactory, factory,
- 30:50Speaker 1: the whole nine yards.
- 30:51Speaker 2: It's amazing what you can do, it is with just
- 30:54Speaker 2: a few lines of code.
- 30:55Speaker 1: PowerShell is a powerful tool.
- 30:57Speaker 2: It is, and this is just the beginning.
- 30:58Speaker 1: This is just the beginning of your PowerShell adventure.
- 31:01Speaker 2: There's always more to learn.
- 31:03Speaker 1: There's always something new to explore, exactly, so keep learning,
- 31:07Speaker 1: keep experimenting, and never stop automating.
- 31:10Speaker 2: Well said, this has been a truly inspiring deep dive.
- 31:13Speaker 1: I'm glad you enjoyed.
- 31:14Speaker 2: It into the world of PowerShell.
- 31:16Speaker 1: It's a fascinating world it is.
- 31:18Speaker 2: Thank you so much for joining me on this journey.
- 31:20Speaker 1: It was my pleasure. And to you listening, Keep exploring,
- 31:24Speaker 1: keep scripting, and who knows what amazing things you'll create
- 31:27Speaker 1: with PowerShell.