PowerShell: Getting Started

View non-AMP version at androidpolice.com

Introduction to PowerShell

Introduction to PowerShell

[Autogenerated] for a successful career in I T. You need to know many things how computers and networks work, how to work with users and how to troubleshoot. To that end, power Shell is a tool that all I t people should know. And that's the goal of this course. Hi, I'm Michael Bender. And welcome to Power Shell Getting started from Pluralsight. In this course, I'll be teaching you the basics of Power Shell so that you can hit the ground running with usable power shell Ninjas skills. So start with an introduction to Power Shell, as well as what you need to know to be successful throughout this course. After the introduction, I'll move into building a fundamental knowledge of power show. I'll cover the main commands. You need to know the basics of the cent tax and much more so that you could become comfortable with using Power shell. Then it's time to get the work. So we're gonna shifts, um, gears and moved to using power shell to gather information on our users and computers. I'll be focusing on working on local systems during that module. Then I'll spend the next module teaching you the basics of remote ing with power shell, especially when working within users. Remote ing is the most effective way to gather information and do simple tasks on a user's system. And all of this leads to the goal of our course building a simple inventory script, using power shell building on the commands and techniques that we've learned through this point, I'll show you how to integrate them into a functional script that could save you time. When troubleshooting and user or computer issues last, I'll wrap up the course with ideas for you to continue your learning.

Who Is This Course For?

[Autogenerated] So who is this course for? Well, it's perfect for anyone who needs to learn power shell to do real world tasks such as gathering remote computer information, performing basic user tasks and troubleshooting system problems. So whether you're an entry level, I t professional with some experience or an I T career student just learning about computers. Or maybe you're a first level support technician who's working with customers, this course is for you. In fact, it's really for anyone that has an entry level interest in Power Shell and wants to move up in the I T world. So what do you need to know coming into this course? While this is a beginner, of course it is important that you know some of the background knowledge going in first, you need a have a basic understanding of networking. You need to know what an I P addresses what ports are, how to computers communicate. You need to have a basic understanding of Windows clients and Windows Server. Since I'm going to be working with some scenarios using Windows 10 and Windows Server 2016 this isn't a huge have to know, but it might make it easier as you're learning power shall toe have this understanding of windows. And last, you need a basic understanding of troubleshooting. While I'm going to cover some troubleshooting techniques and tools for finding information, you should have an understanding of how to troubleshoot a problem. My guess is that many of you will be just fine. I'd recommend diving into modules two and three and seeing how it goes if you need additional learning. There's plenty of courses on Pluralsight that cover all of these. So that is what you need to know. You might be asking, What don't you need to know and what that is is You don't have toe have background in scripting or a background in programming. I'm going to be teaching you power shell from the ground up. So no additional knowledge of scripting or programming languages is necessary if you have this more power to you as it will probably smooth the path as I go into scripting and mawr complex commands that might include things such as logic and variables. So with that, let's get started

What Is PowerShell?

[Autogenerated] So you might be asking yourself What is PowerShell? Is it a command line shell? Is it a scripting language? What exactly is it? Well, it's sort of all of those. While many people see it as a scripting language or a command line interface, those air on Lee part of the puzzle. It's really an execution engine that provides the ability for you. Thio interface with your environment using a variety of tools. So it may be easier to show you than to explain to you what power shell is. This is what many people see is power shell in here we have the Windows power shell console that allows us to run different commands, such as in this case, get dash service we-can run scripts we-can perform many tasks from this interface. Along with this, we have the newer power shell corps and in power shall core we-can do many of the same things we-can run, get dash service and we could see the services that are available on here. Remember PowerShell core? That's the newer version of Power shell that allows us to run this on multiple platforms. So those were the two command line interfaces We also have the Windows power shall I S C or the integrated scripting engine. And this was the original on Built in editor for editing power Shell scripts. We-can also run power shell commands from here as well. So this is a tool that we can use on our Windows system that's built in the newer tool that many people are using his visual studio code. So visual studio code is a new cross platform editor that runs on windows Linux, Mac OS. IT has extensions that we-can built in. In this case, we see we have the power shell extension built in UI. See, we're able Teoh add different commands into the interface. We-can also run those if we want to see how those work so very similar to the I S. E. And it gives us a lot more flexibility and it gives us a lot more tooling as we move into the arena for building our scripts. Another area that you might not see is being power shell and working with power. Shell is server manager on Windows Server. So, server manager, as I mentioned before, all of the features that are built into Windows server are accessible using power shell and server manager uses power shell on the back end whenever it issues anything. So just starting or stopping a service or working with a specific feature. And the last tool that I want to show you that uses power shell is Windows Admin Center. So Windows Admin Center is the new Administrative center for Working with Windows Server and also integrates with Microsoft Azure, so it allows you to get access to everything in your environment. The reason I'm mentioning this, of course. Windows Admin Center uses power show on the back end to do all of the administration. Why is this all important? Because it's important for you to know that there's a number of tools available for you toe work with Power Shell. And that power shell is being used by many of the tools in the box to work with systems in your Windows environment. And that's the different tools that we're going to be running through As we learn power Shell

Windows PowerShell and PowerShell Core

[Autogenerated] as we saw in our demo, there are a couple of important councils that we use working with power shell, and the first thing the one that's been along since the beginning is Windows Power Shell and Windows. Power Shell is based on the dot net stand work. So uses the full dot net framework that's built inside of Windows. It's also built into windows, so when you get a copy of Windows, it has Windows Power Shell ready for you to go. One of the downsides that we're finding is that Windows Power Shell is on Lee on Windows. You can't install it on a Mac. You can't run it on Linux. While you can use Windows power shell toe work with some of those systems, it's only going to run on a Windows system. The other thing with Windows Power Shell. IT is feature complete, and what that means is that no further development is going on for Windows Power Shell to improve it. So there's not gonna be a newer version. It will get security updates and those sorts of things, but it really is. Here's the point where it's completed and ready to G O and it does have a full set off the Windows commands that it can work with. So those air all built in and ready to go inside of Windows Power Shell. So the new kid on the box is power. Shell Corps and Power Show Core is based on dot net Core, which is a smaller, lightweight version of DOT Net that's designed to run across platform. So it's downloadable from Git Hub, and the beauty of it is that it runs on Windows, Linux and Mac OS. So Power Shell Corps is really the future of working with power Shell because it allows you to use power shell on any platform that you're looking at. It's also open source. It's an open source project that is available for you to work with on Git Hub. So many of the features and tools that you'll see within Power Shell Corps are actually built out by members of the power shell community that are contributing to make that software better. And one of the things with power shell corps and this is getting better is that it does have a subset off the Windows commands available to IT. Since this will run on Linux systems and Mac OS, it doesn't have all of the windows specific commands in IT

Demo: Installing PowerShell 7 on Windows 10

[Autogenerated] Now I'm gonna walk you through the process of actually installing power Shell seven on Windows 10. We're going to go through the process, show you where to get the download installer, and then we're going to perform the actual installation. What's dive on in the best place to start when you're wanting to download power Shell seven or Power Shell is going out to get hub dot com slash power shell slash power shell. This is where all of the open source development happens and where you can find the execute doubles for installing power shell. So if we scroll down here, you notice we have a huge list of all of the different operating systems that we can install this on in our case work installing the windows acts 64 version. I'm gonna go ahead and go to the stable version, grab the M s. I download that While that's downloading, I want to show you some other ways that you can install power show as well. So if we go to the instructions here, this is going to take us out to docks on Microsoft dot com. You see on the left side you'll notice it shows you different ways for installing power show on Linux. Mac OS on arm were interested in Windows right now. So as you go down further in your power shell journey and you get mawr comfortable with working with the command line, chances are you might want to use the command line to automate or make it easier for you to do the installs. So this is a great place for you. Go to to see all of the different ways so you can actually use the command line and use MSC exact I dxy Thio Call the package for Power Shell. There's a number of different options here that you can use now. Let's go back and open up our execute herbal for power Shell seven. So here we have our set up. I'll click next. It's going to give me the where to install. It will leave the installation path for PowerShell seven, and it gives me some options here. I'm gonna leave enable Power Shell Ri moting unchecked because we'll do that in a later demo Click. Next will go install and now it will ask us to prompt that is elevated. It'll installed as administrator once it's completed the installation, then we'll be able to go in and actually start working with PowerShell. Seven. I'll go ahead and choose launch so we can see what the council looks like. Ah, click finish And there we go. Now we're running power Shell 703 and that's installing power Shell.

Why You Need to Know PowerShell

[Autogenerated] So now that you have a better idea of what power Shell is, let's discuss why you need to know IT first. It's not really going anywhere. Microsoft is all in on power shell in regards to managing Windows, every application from exchange to sequel Toe Active Directory is built with power shell as a basis for the administration of those products by the product teams. So when you use many of the gooey server tools like maybe Windows Admin center or server admin, it's using power shell under the covers to perform that work. For I T. Pros, automation is the key to a long career and power shell is the tool to get started automating your environment. So if you learn toe automate repetitive tasks, you're going toe. Have a long shelf life in I T. And now, with the introduction of power Shell Corps and also visual studio code, you could manage script and automate using power shell from Windows, Linux and Mac OS. It's truly any platform anywhere that you can do your work from. There are many things that can just not be performed, so we find that it is better than the gooey because There are things such as active directory tasks as well as things in office 3 65 and Azure that are much easier to do with Power Shell. And there are some things that you can Onley do with Power Shell, so that's a good reason to know IT. For those looking to take a Microsoft certification class, Power Shell is a must know on those exams. So all of the new exams you need to know power show in order to be successful on those and last just about everybody's learning it and using it within their organizations, especially those running windows, and that have been Windows administrators for either a long or short period of time. If you don't, someone else surely will, and you may be up against that person the next time you're going for a specific job. So let's take a look at how power shall convey make life easier

Demo: Using PowerShell to Report on Stopped Server Services

[Autogenerated] in this demo, we're going to see how easy it is to gather information about services on a computer and send that information to a C S V file formatted for your boss to use. Later, we're gonna focus on using the get dash Service Command and also show you how to use where dash object and select ash object to work with power shell. So let's get to it. Here we are on the admin work station and I've got power Shell Corps Council opened up. And because I wanna look for services and find the stop services and provide those to my boss, I'm going to start with the git Dash Service Command. So we're gonna go ahead and type in, get dash service. And, as you can see here, it brings back all of the stopped and started services that air running on our system, giving us a default view. So I want to do drill down into this a little bit more. I just want to stop services. And I just wanted to show the name of the service and its state. So we're going to start out again. We're going to do get dash service I'm gonna end with a pipe and then I'm going to do a carriage return here, and it's gonna bring up another line. This allows me to do multi line power shell commands. So we'll put in using where dash object. And I'm simply calling where dash object using the status property is equal to stop. So this is gonna bring all of the services that are stopped back to me. And then what I want to dio is I want to run that. So now you see, basically brought that list of all the stops services. IT gives me both of the names as well. So we're gonna run through that again because what we want to do at this point is we want to further refine that down. We're still going to use the where dash object, and then I'm gonna pipe that into select ash object. So the output that I'm going to get out to the console screen is on. Lee gonna have the name and the stop state because that's what I want tohave in the report for my boss. So at this point, what we're gonna do is I'm gonna create a variable and in that variable. I'm gonna put all of the output that we just got. So we're gonna use that same command to get dash service piping that into the wear object, looking for the status equal to stop and then selecting out that object with the name of the status. So if I just call that variable and hit enter, you'll see that it brings back the output. So now that is stored inside that variable. And I can use that now to send that into on out dash file. So I'm doing out dash file and what it's doing is it's taking the output, and it's sending it to ah, file called services dot C s V. We'll go ahead and run that. And now what we're gonna do is we're gonna call, note, pad and call that services dot C S V and we see here. Okay, IT brought up all of those in that outputs in there, but if you look at that, that's not necessarily a comma separated value file. So if we brought this into excel, it might not be what we're looking for. So what we're gonna dio is we're gonna do the same thing. We're gonna pipe it into export Dash C S V and we'll put that into services to dot C S V because what this does and we'll go ahead and open this up and we'll do a get dash content so that we can view this in the console. You see that? It brings it up for us. We see that it's comma separated, it's got ahead a row. And now if we brought this up and we opened this up in excel, then we would be good to go, and our boss would have a report that he could use. So that's really show you very quickly the power of how we can get information with power, showing how we can quickly work with that and get exactly what we want out of it.

Course Demo Environment

[Autogenerated] for this course, I'll be using three virtual machines for our demos. The first is our administrative work station that's running Windows 10. IT has Windows Power shall Version five. IT has the remote server administration tools for Windows 10. It's also joined into the company dot p r I active directory domain, and we also have visual studio code, and this is gonna be the system we're going to use primarily throughout the course. The second VM is running Windows Server 2019 with active directory installed in the file and print services. It is also running Windows PowerShell version five, and it will be the target for many of our remote computer demonstrations. The last machine will be a remote Windows 10 client that's also joined to the domain. It's gonna be used as a target for our demonstrations as well. So that's the environment that I'm going to use throughout the course. So now that you have an idea of what the layout is for our environment, let's take a look at the admin workstation. So in this demo, I'm going toe log into my environment, and we're gonna take a look at the environment. We're gonna introduce you the Windows Power shell console. I'm gonna install the are sad tools on windows. So this will give us a set of tools that we-can usedto work with servers within our environment. And then we're going to introduce you to power Shell Corps and the council that's used with that. So let's go ahead and jump on in. Now, here I am on my admin work station. So the first thing I want to do is I wanna customize the Windows Power Shell Council and I'll show you how to do it on PowerShell cores. Well, I'm gonna go down to my task bar where I have my Windows Power Shell icon. If I right-click on this notice that I could run this as administrator, I could run the I S C as administrator UI or just run the I S C. I'm going to choose to run as administrator. And of course, it's going to come up with a u A. C prompt and I'm going to choose Yes, And then I'm gonna maximize this. I'm gonna go up to the bar. I'm gonna right-click go properties, and this brings up the properties for Windows Power Shell I'm gonna increase the font size, so it's a little bit easier for everybody to see. I could go to the layout and this will change the layout for my screen. So this will allow me to set the width height. I can have it automatically wrap the text if I want, I could modify the colors as well for everything. So we're gonna leave everything as default. For the time being, I'm gonna click. Okay, So while I'm in here, I want to check to see what version of power show I'm running. So to a P s version table and notice. It's the 5.1 dot 17763.1 version. You see that it's compatible with all of the versions of Power Shell, so I should be good to go with this version. Next thing what we're gonna do is we're gonna install the remote server administration tools. But before we do that, I want to see how Maney commands are loaded onto this system. So I'm gonna do a git dash command. If I put that into parentheses and type and count, it comes back with 1577 commands are available and installed inside of Windows Power Shell. So let's jump over to PowerShell core. And if I do the same thing here, if I do a P s version table, you'll see that it's 61. That three. IT tells us the compatible version, So it's the same ones as we saw as well. I'm going to do the same command here to see what command, how maney commands we have. We do a git dash command UI. See, it's 12 18 so it's about 300 or so lower than the Windows Power Shell. That's because there are certain commands that aren't built into Power Shell Corp. Because of the difference between using the dot net standard framework and the dot net core. Now that we've taken a look at Windows Power Shell and Power Shell Corps, the council's let's go through the process for downloading the remote server administration tools. So I'm gonna go out to my Web browser. I'm gonna search in Microsoft dot com and going-to search for our set Windows 10 download, and that will bring up the first-one Here is most often times the correct one, so we have the remote server administration tools. So we pick our language got-to click download here and notice that it gives me a number of different options here x 64 or x 86 depending on the platform of the admin work station. And then it's gonna have different builds for different versions of Windows 10 and notice. It also has one here for Windows Server 2016 as well. So I'm gonna go and choose 3 18 03 version, Click next, and then I would go through and it's going to go through and download this. Since I've already downloaded this, we're just going to go over to our downloads and I'm going to double-click on be executed URL and that allow me to go through the standalone installer. So what this is going to install is it's going to install all of the standalone tools that we can use toe manage Windows Server. It's also along with those gonna install all of the power shell modules that go along with all those tools as well. So what this gives us is a couple of things. One if we needed to use the gooey tools, I could use those to manage my server, and the second thing that it gives me is now I have all of the power shell modules for things like DNA s and D HCP and active directory that if I want to research those which we're gonna learn about in the next module, I conduce to that from my administrative work station. This process can take a while for the update to get installed. So once that's installed, will come back and we'll take a look at how that has made a change to our power shell councils and the number of commands that we have. Now that that's completed, it's gonna have us restart. So I'm gonna go ahead and restart, and when we come back, we'll go ahead and we'll log back in and we'll take a look at the changes that we have on our system. Now that I'm back in here, I'm going to do that same command. Get dash command count to see how many we have and we see now that's 28 47. So ah, huge number of commands have been added into and made available for us to use inside of Windows Power shell. So I'm just gonna do a get dash command here, and then I'm gonna use dash name, and I'm simply gonna put in de HCP. So notice we have all of these commands for D H C P server. Those are ones that I knew that would be added in is part of the are set. So we know that we have those available, so that's a little bit about getting that set up. Get your admin station set up. So now that we have this all set up, we're gonna be ready to dive in tow, learning about power shell.

PowerShell Basics

What We'll Cover

[Autogenerated] in this module. I'm going to cover the basics of using power shell what you need to know to get working with power shell and using it on a day to day work basis. So to start this module, I'll break down power shell commands and discuss the important components you need to know, like command sent tax parameters and then aliases. After we do that, I'm going to dive into the help components of Power Shell. This is probably one of the most important parts of power shell. Microsoft built the help in Power Shell to provide you the most of what you need to know without leaving the shell. I'll introduce you to get dash help along with get Dash Command and get Dash Member. With these three commands, you're on your way to becoming power shell Proficient. I'll use all three of these to explore the Power Shell Council and find the answers in the box. No search engine is required along the way. I'll introduce you toe other helpful command, such as get dash history, get Dash Alias, just to name a few. Next, I'll dive into the pipeline and power shell. This is really where things start toe happen with power shell and where you can get some serious work done to really understand the pipeline and how it works. You need to understand how power shell works with data that it uses power. Shell treats all data as objects that may used to their full potential in power shell. I've got a lot to cover, so let's get the learning the basics off Power Shell.

Command Basics

[Autogenerated] in power shell commands are based on a specific cent tax. This syntax is important as it allows you to use power shell more effectively and efficiently as you go along. To start, all commands should be using this syntax of verb. Dash known, I say, should, as some people may create custom built tools that don't follow the best practices of verb dash. Now for what I'll be covering. All commands will follow this format, and you should follow. This is you begin creating your own power shell tools. The reason we lay this format out is so that as we build community tools and as we share our knowledge, we're all coming from the same basic fundamentals with power shell. So at a very basic level, with power shell, you do something to something. So let's say I want to get information about the verbs that are available for use in Power Shell. I'd use a commandment called get dash verb and notice. I put the dash in there that is very common, and when you hear people talking about power shell, they don't just say get verb. They say Get dash verb to enforce that sent tax and how that is actually going to be put into the council before I dive into the council. Let's talk about another piece of a power shell command, and that's the parameter or parameters. So what parameters do for us? Is there used for us to pass information into our power shell commands so that we have information that we can use for the command to use to do its work? And so all of our parameters are gonna be called using a dash. So you see here get dash service dash computer name and then the value for that parameter. So Power Shell knows that when you put a dash and then you have a string following it, that that is a parameter, and then the next value is going to be the value that's used for that parameter. So common parameters that we have our dash computer name and dash file

Demo: Exploring PowerShell Verbs

[Autogenerated] So in this demo will look at the verbs and power shell and show you how to make sense of these. So let's dive into the council. So the best way to see what verbs air available in power shell is to simply type in get dash verb. I'm gonna pipe that into mawr, and that is going to give us the listing of all of the verb so you can see it gives us the verb. There's an alias prefix, which is a shortened form of the verb UI seethe grouping. So all the verbs are grouped into different areas such as common communication security. And then we have the description for each verb so you can get mawr detailed understanding of each of the verbs. So as we go through this, it will go through all of the listing for all of the verbs that are available in power shell. So let's say I want to get a little bit more in depth on the set verb. So I put in get dash verb. The parameter dash verb was set as the value. I'm gonna pipe that again into more on that list for me, The information about the set verb. If I wanna look at that a little bit differently, I often like to look at things in a format list formatting for the output we see it gives us the same, but it's a little bit easier for us to read. So that's how we would take a look at all of the verbs and power shell and then also look at a specific verb. Let's say you wanted to see all of the verbs that are included in the security group. Easy way to do that is doing get dash verb using the parameter Dash group. Specify the group name of Security again. Going to put that into a format dash list and that list all of those out there for me. So that's how we'd investigate in the council. Ah, great resource for you to check out would be to go out to Doc's done Microsoft dot com. So if we go out to a k a dot M s slash PS verbs that will bring up the doc, stop Microsoft dot com page, where we have the documentation for the approved verbs for your power shell commands. So this is kind of a long read. But it's a really important read for you to really get a good understanding off the verbs that are used in power shell. So that's verbs. So the next thing we want to take a look at is how we work with aliases and parameters.

Demo: Working with Aliases and Parameters

[Autogenerated] these is way to take a look at aliases and parameters is by taking a look at a command and seeing how we can use aliases and parameters with that. So the command we're gonna uses get dash service. I have a couple parameters in in here Dash name. So I'm looking for all the services, beginning with M notice. I'm using a wild card that allows me to do a wildcard search there. Dash computer name, which is a common parameter and notice I have client no one comma D C. 01 This allows me to put in multiple values to be used by the get dash Service Command. And I do that by separating the values with a comma. So when I run this notice, it brings back all of the information for this specific command. You'll notice that there's a number of these services that are doubled up because it did go out to those two computers. So let's say I want to start shorting these up and I want to take a look at some aliases. So the easiest way to do that is do a get dash alias. I'm gonna pipe that into Mawr and that's going to give me the listing of all of the aliases that are available in power Shell. So basically, alias is a shortened form of a command, so it allows us to type in fewer keystrokes to get a specific command that we're looking for. So this is a great place to look for shortcuts when you're doing Rheal time console commands the thing to remember what aliases. You don't want to use aliases in your scripts. These air perfectly fine when you're doing day to day work. But inside of a script, you should always put the full command. So now what I want to do is I want to take a look. I want to find an alias that applies to commands that deal with service that use the service noun. So I put in a dash definition parameter off service notice it comes back with three. So G s V is the alias. Forget dash service. So now let's put that into our command. So we replace get dash service, we do a G S V. We put in the same parameters. And when we go ahead and run this we see it runs in IT performs the same thing for us. So we see how we were able to shorten that up. So the next thing we could do is we could start working with the parameters and use what's called positional parameters. So with positional parameters, what happens with that is that we can leave out specific parameters because of the position that they are within the command. So if we take a look at the help, forget dash service. We see we have a cent tax here. And if you go down to the third cent tax, you see the dash computer name is the first you see it, the first sent tax, you see, name is the first and computer name is the second. So what that means is I can do some things to shorten this up. So instead of having the type the dash name parameter, I could simply put in G S V. I can put in my wildcard search of em dollar I can put in the dash computer name and it will perform the same task. The other thing that I could do with parameters is I can shorten parameters. So let's say I don't want to type out the entire dash computer name. What I can do is I can shorten that to dash comp and you'll see here it performs the exact same thing, so that covers aliases and parameters and verb. So that should give you a better idea of how toe work within power shell and how to shorten up some of your commands.

3 Important Commands

[Autogenerated] when it comes to learning power Shell, there are three commands everyone needs to know. Get dash command, get dash help and get Dash Member The reason these air so important is that these allow you to find the answers. You need toe work with power shell in the box. Meaning you don't have to go out to a search engine. You don't need to search the Internet. You can find everything within the council. They'll also help you understand how power shell commands work with objects. So the best way to find out how to do something within power shell is to use these commands to explore the council. So the first of these commands is get dash command and get dash. Command is basically used to search for the installed commands within power shell. So we see some examples here we could use git dash command we-can use a parameter of dash verb to just get the commands that have the get verb and that also then use a noun that includes DNA s. We could also use get dash command to look forward by name and also by command tight. So the next one is get dash help. So with get dash help. This allows us to see how we use a specific command that we found so displays the help information. So if you're familiar with man in Linux, get dash help is the equivalent of that inside of power shelf. So it allows us to be able to search our power shell commands as well, so we can not only get help for a specific command, we can also use it as a way to search for commands that we have within the council.

Demo: Finding Answers in the PowerShell Console

[Autogenerated] in this demo, I'll show you how to use get dash help and get Dash Command to explore the Power Shell Council for answers. So let's dive into the council. So the easiest thing to do is I'm gonna go here. I'm going to type in, get dash help to get information about the health command. Let's put that into dash more and you'll see that a walk us through, so it'll give us all of the help. Information about the power shall help system, so it'll give us a short descriptions, long descriptions, everything about all of the different commands. I like the examples that it shows at the end, so we see examples. So that's a little bit about the help command. So you might want to explore that when you get a chance. So let's say I want to use get dash help to be able to explore and find out what commands are available. Just like I would do with get dash Command. I could type and get dash help. I'm looking for the ones that are related to service. Pipe that into more and you'll see it comes back with the list of all of the commands that contains service in it. And it did that because of how I use the wild cards with that. So another way that I could take a look at this is I can also do help get dash service, and that will allow me to look at that singular service. Help is a form of an alias that what it does is it shortens get dash help, do help. But it also adds in the more so that it'll go through each screen by screen so you don't have to type in mawr at the end of your commands. When you're using help for that, you'll notice here underneath the remarks that says, Get that help Can't find the help files for this command. URL IT. That's because I haven't updated the help files. So what I need to do is I need to go and run Power shell as the administrator and I type in update dash help and what this does. This will basically go out to Microsoft, and it will download all the latest helpful aisles, so this can take a while for this to go on, depending on what you have installed. Now that's finished up. We see we do have an error here. From time to time, you'll find things that just simply won't update. So we're just gonna move along. And what I'm gonna do is I'm gonna do a clear screen. And from this point, let's type in that command we had before get dashed service. And now when we put that in, we see that it has the help for us and we can go through. And it shows us all the help for the get dash Service Command. So one of the things that I like to do is I like to do a dash examples. So if I run that same command, put dash examples at the end, it'll give me simply the examples of how to use this. I think this is such an easy and great way to dive into power, showing how to really get to use the commands because it gives you real life examples of how you can use these, and they're often going to go from example. One is gonna be like the most general one to getting to be very specific in the commands. And so you see, this one has a ton of examples for you to go through. If you want to see the full documentation for the command, I'm going to simply go back. I'm doing an up arrow to go back to the previous commands I'll type in full. This is going to give me the full documentation and notice here. This gives us the full parameter information, all the information we need to really dive into using these commands in the parameters with, um are going to be fine when using full. And so we'll go ahead and we'll click out of that. And one of the things to remember with this is that let's say you're familiar with Lennox and you're familiar with man. If I type and get dashed, service notice gives me the same sort of help. So what basically happened there is that we've a liest man so that IT aliases to the get dash help command for that. And the next thing that is a great help is the about files. So the about files are really the detailed documentation of how the background of power shell works. So if I type in help and just about, it's going to come back with a list of all of the about file. So these air really the How do we use power shell? So if there's a specific thing that you want to look at, so let's say you want to see how to use event logs. There's an about underscore event logs that describes all of that information for you. So that's how you get the information in the box. So using get dash help or help and then using the about files.

Demo: Researching Commands with Get-Command

[Autogenerated] Let's take a look at researching commands with get Dash Command. We're going to do help get Dash Command and that will pull up the help file. Forget Dash Command so we can see we get our cent tax here, kids, there's a detailed description, related links, marks all of the things that we would expect from help. I like to go straight to dash examples. So I'm gonna put in the switch parameter for examples. And you see, it gives us a bunch of examples for how to use the command. I love this. I think it's one of the best features in power. Shower makes it super easy for you to dive in and start working with commands. And you're gonna find the examples go from the most general to the most complex. So they give you a ton of different scenarios that you can walk through and they give you background on how everything works. So if I want to see all of the commands that I have loaded on a system, I could do a git dash command will pipe that into mawr, and that will start pulling up all of the command so you can see, there's a ton of command. So we've got aliases. Functions as we keep going through here will finally get to the command. Let's because we have thousands of them that are built in here. As we keep going through here, you'll see there's a number of different we get to the command. Let's so I'm gonna control C to exit out of the running command. So let's say I want to get the commands that are related to the verb knew I could do a get dash command type in the parameter dash verb click new and you see it gives me a number of commands that are related to just knew. So you can see here how we can go through we-can search through these. So let's say I want to see how many commands do I have in the system that are functions. So I put in dash command type put in function. I'm gonna pipe that into another command called measured ash object, and you can see there there are 1722 functions that are built in there, so there's a ton of functions that you can use within the system. So what I wanna do is I want to find a command that's gonna allow me to be able to work with i p address configurations. So we're gonna do a get dash command for the name. I'm gonna put in a search parameter put in wild card I p wild card, and we'll go ahead and put that in. We see. Oh, there is a ton of information there. So we see a number of different things that are in here. Net security. UI cease. Um, I pam server UI cease, um, net controller UI cease. Um net TCP i p. So a lot of different things related to net, which is probably networking. So what I'm gonna do is I'm gonna further refine this, and we're gonna look for a module that starts with net. So maybe that will refine that down for us so we can see that. Okay, it has further refined that down to us and net. TCP I p. That looks like probably a good module. That might be what I'm looking for. So we'll go ahead and clear screen again here, and we'll go back up to our command and then I could put TCP I ___ in here and we see There we go. So we have a list off functions that are available Force toe work with net TCP I p UI See, we've got a net I p address net I p address configuration. We have ones for I p p four i p b six. So we've really drilled down into to find what are the commands that we're looking for? Then at this point, what we would do is we would dive into I'm guessing the get dash net I p address might be the one we're looking for. So I'm gonna go ahead and use our friend help put in get dash net I p address and we see that that is a command that that gives us the I p address configuration for I P before I p v six. If I wanted to see examples of how that works, I could put in the examples here, and it gives me examples of how to use the get dash net I P address. Now let's go ahead and run that command to see what it does for us. We see that it does give us i p address information. So that's how we would go about using get Dash Command to search for commands within power shell

Demo: Documenting Your Work in the PowerShell Console

[Autogenerated] In our next demo, you'll learn how to use built in commands for documenting your work in the council. Because a lot of times you'll be doing a lot of work and then you'll be like, Hey, I want to keep track of all those commands that I just ran in there or you're running through a process and you're like, Hey, I want to capture whatever the output is. And if there's errors of stuff that's going on, so we're gonna show you how to do that within the council. So the first thing what I'm gonna do is I'm gonna create a new directory called Transcripts Underneath the Scripts directory. I'm using M D, which is short for make directory, and that's going to create a folder to store my stuff in. So now I want to investigate, get Dash history so we'll put in help get dash history so that we can see what the command does. So IT gives us the cent tax of description everything that we would use for checking this out with help. So we see that we have some parameters that we can use. We could do an I D. We could do account. So now what we want to dio is let's take a look at the actual history that we have in our system. So if I type in get dash history, it will display the history of all the commands that have been listed previous. So you'll see there's an I D and then the command line info there. Now what I could do is if I want to invoke, say, Number 24. Say it's a really long command and I want to run it again, but I don't want to type IT. I could do an invoked ash history. I could put the I D number in and it will go ahead and auto run that command. So pretty cool how you could go through hit that I d number and bring that command and have it run based off of the history. Then if I want Thio, take a look at the history again and I want to send that out to a file. So let's say I want to keep track of all these commands. So I've been running these commands and eventually they're gonna make their way into a script. So instead of having to re type all these Aiken, send these out to a text file. So I pipe this in tow out dash file. Then when I go and open that file and note bad, what we'll see is there are all of our command. So if there were some of these commands I wanted, I could simply copy those. And I could paste them into whatever scripting tool I'm utilizing for that. So quick and easy way for us to be ableto output those from the PowerShell Council into something that we could use a far-as a document. Next. Let's say we want to just clear our history and get rid of whatever is in there. I could just type in clear dash history. And if I run, get dash history again. We'll see that our history is gone. So that's how we use git Dash history. So now let's take a look at start dash Transcript. So type in help start dash transcript and that'll show me the help file for using start dash transcript, and basically this is a transcription tool that allows you to basically capture everything that's in the console window. So not only the commands but IT also has any output. If you have errors that will capture errors. So it's a great tool for debugging things as you're running through commands. So we'll go down here will type in start Dash transcript to start the transcription process. In this case, I'm specifying the path location that I wanted to go to inside the Transcripts folder. I'm putting the dash a pen because that will then add this to any transcription file to the end of any transcription file that I have. So click add. So now that started that process. So I'm just gonna type in, get bashed service and find the properties where the status has stopped just to create some traffic here and we'll see that it goes through and it will show that output, not what I want to do is I want to stop the transcription process and open up that file in note pad. So when I open that file up UI see, there's our transcription, so notice that the top it does give us a lot of information. Who was running this under what context from what machine? The application? Ah, bunch of different pieces of information that you can use as you refer back to this. And then if we go down, we see that. Okay, The command that we ran is up there. We see the output. So this is a great way to track your work and to be able to keep a record of things that are going on. Another way that this really helps out is let's say you're running the command and you get in a bunch of errors and you wanna work with somebody on your team to help you troubleshoot this. You could send him the transcript file. It would have the commands you're running and the errors, and they could look at that and be able to give you feedback. So that's get history and start dash Transcript.

Objects in PowerShell

[Autogenerated] Why is power shell different? Because objects make power shell different. It's because power shows an object oriented language. Unlike other scripting languages that rely on parsing text to get things done, Power show uses objects as its output. So if we think about Power Shell, we already talked about that. It's not text base that it's based on being object orientated is that with objects, they have properties that make them up, and they have methods that you can perform actions against them. So if we take, for example, think about an apple as an object. So with an apple, we know that the color is red. We know that its shape is somewhat round, and we know that it's skin is editable these air, all properties of an apple. So if you were to hold on Apple, you would be able to see Okay, Hey, this is kind of round. Hey, the color is red. If it's a red apple. Oh, if I try eating it, I could tell that the skin is editable in that. So just like the objects that we work within Power shell, they have properties as well. So the best way to visualize objects in power Shell is to view the data in a table format. Power showplaces all of the data from commands into a collection or a table to store that data. In the case of what we have here, we're using get dash service and it's providing us information about the services on a computer. So each row of the table is an object with properties are attributes to sign to IT. These properties all have values that are stored in the table and then could be accessed as we're working with power shell. And this is the stuff that we're really looking for. This is how we really start doing work with Power shelf. So how do you find all of these properties attached to an object so you can work with him? That's where the third command get. Dash Member comes in. So with get Dash member, this allows us to get the properties and methods of objects that are the output off a specific command. So it's used to see what makes up an object. So to use this UI use, get dash service and then UI pipe that into get dash member and that will show us All of the properties that are available on an object single commands air. Great. They provide us information, could do work and a host of other things. However, the rial power and power shell comes when we use the pipeline. So pipe lining PowerShell is a way to send the output of one command into a second command and this allows you to doom or complex work. So in this case, we get something and then we take the output of that and we may do something like sort that something. And then from that output UI then do something so we can use our data along the pipeline, all of the objects passing through to be able to get work done. So when we're looking at pipe lining and power shell, we see the example that we showed during the introduction we showed you where we took get dash service UI pipe that into where dash object that allowed us to simply pull out all of the objects where the status was equal to stop. And then what we could do is we could pipe that into a start dash service In the real world, this command might not be exactly what you want to do. You might want to do some further filtering, but it shows you the power off pipe lining and how we can use information going through the pipeline to do work. So that's where our next demo is gonna come in. We're gonna jump into using the pipeline, so we'll show you how to do basic pipe lining so that you have an understanding of how the pipeline works.

Demo: Finding Object Properties with Get-Member

[Autogenerated] So in this demo, we're going to take a look at how we use git Dash member to find object properties within power. Shell through the process will take a look at working with the pipeline and things involved with sending data and objects through the pipeline. So let's jump into our demo in the Power Shell Council. I'm gonna go ahead and type and help get Dash Member to take a look at the get dash Member Command. So we see that this is a command that gets the properties and methods off objects so we'll go ahead and type in get dash service. And how we use get Dash Member is that we take the command UI run IT and UI pipe it into get Dash Member. So what's important here is that the command has to run properly. Forget Dash Member to be able to find the membership in this case, get that service is going to do that for us. So we see what it comes back with. It comes back with a list of alias properties. So these air aliases for the property names we see their name is equal tow service name. We have methods, and then we have all of the properties that are available on that object. So besides the things that we normally just see when we use get that service, we have a number of other properties that have values that are associated with those objects as they come through. So there's a lot more information that's attached to the data that we have available to us than what we're just seeing being output to the screen. So if we go ahead and type in, get dash service, pipe that into a select ash object, I'm going to take the name, machine name and status, because that's what I want to see as my output. So you see that it's come back with just the name, machine name and status. So now if I run, get that. Sure it's again, and then we do that same select command. And if we send that into get dash member, notice that my membership is shrunk, this isn't really important here because as soon as you use select dash object, what that does is it select all of those properties out of the objects that are coming across the pipeline, so as soon as you select out just machine name, name and status. The rest of the properties that were associate IT are no longer there, so we can see that in the table. So that's really important as you're working with this. So now if UI type this in again, But this time we're using where Dash object, looking for the status where it's equal to stop it will bring back the information as we're used to seeing with the stop services. So now if I take that same command, get dash service, running it against two different computers. CLI No. One in D. C. 01 and I'm going to use that where dash object. And that way, what it's going to do is throw. Objects that are coming across the pipeline are only those objects where the services stopped. Then it's going to go in, and it's going to do a select dash object. So it's gonna pull out just the name, machine, name and status toe pass along to the next command, and the next command is gonna have a consort that information using sort, dash object based on the property being the machine name. And so when we run that we see there's our output. So we have the name of all of our services. We see the machine name CLI No one stopped and we see that it's sorted IT by machine name. So that's how we can use git Dash member to find those properties. So as you're working with commands and you're wanting to find more information, type the command and pipe it into get Dash member on. Then you can use those other commands, like select Ash Object where dash, object and sort dash object to further refine what's coming through the pipeline.

Wrap Up

[Autogenerated] that was a long module on power shell basics. I wanted to make sure that we covered much of the basic tasks you'll need to be successful with the rest of the course as well as's with learning power shell from the ground up. I covered too many things to try and capture all of those in a wrap up, so I'm gonna focus on the major points you need to take away from the module. First up Cent tax. Remember, Most power shell commands use verb dash, known as they're naming cent tax. This is super important toe. Understand it. It makes it easier for you toe. Understand what commands you might be needing to use and how to use them properly. Also, make sure that you understand how parameters air used and the different techniques for shortening commands with aliases, positional parameters and shortening of parameters. UI introduce you to the first of many tools within power shell get dash help or help for short. This is one of the most important commands as it allows you to be able to research and learned power shell in the shell without having to leave. I recommend running help on each command before you use it, so you know how it works. And remember, Dash examples is a good way to skip the line and go right to how commands work. Next, I showed you get Dash Command. This is the great tool for for finding all the commands available on your Windows system. You can use parameters to search for new tools without having to know the name of the tool. Remember to use the asterisk, a k a. The wild card to perform a general to specific search. Another helpful tool is using git Dash history and the other dash. History commands toe work with commands you've executed in the shell. This could be a riel timesaver, one documenting processes, building scripts or just keeping track of what you've worked within power shell. Just remember to grab your history before you close the shell or you'll lose IT, and the process that adds power to power shell is the pipeline and the process of pipe lining. Remember this allows you to send the output, are objects of one command into another, and remember power Shell treats all data as objects so you can work with your data through the pipeline and do some amazing bangs. And last remember, get Dash Member is the best way for you to be able to find out what objects are assigned and available for the output from a specific command. And there you go, the basics of power shell. I hope this gave you a really great foundation. As next up in the next module, we're going to dive into gathering information with Power Shell so that you can start putting power show tow, work to find information and do work so we'll see in the next module.

Gathering Information with PowerShell

What We'll Cover

[Autogenerated] I can't get out to the internet. Where are my files? I can't find my spreadsheet. My computer isn't working. If you spend any amount of time working with end users or in a support role, these air very familiar refrains. Solving problems is what a career in I T involves, and the first up to solving a problem is gathering information to find a solution. So that's what I'll cover in this module. Gathering information with Power Shell to start I'm going toe layout for you, a basic troubleshooting methodology that I use every day. It will help you lay the foundation for the rest of the modules and the topics we're going to cover. Then I'll dive in with both feet into gathering information with Power Shell. I'll be using a lot of the commands with the verb get dash. Since that is the key verb for gathering information, I'll break down areas you should know that will give you skills you can start using right away. So let's get to talking about gathering information with power Shell

Troubleshooting Made Simple

[Autogenerated] most troubleshooting is common sense. You have a problem. You need to find a solution. You'll find many different ways of describing a methodology, but they all break down into this simple form. First, we need to identify the issue. What's really happening? Vague issues like the servers slow or the internet is broken aren't really useful, but they are a common starting place. Narrowing down specific symptoms like error messages, affected systems and applications. Or the time of day helps you to move to the next step of what's causing the symptom to occur. This step is often overlooked when I T professionals just jump right into the computer is slow to you should reboot to restart the application. While it's a common question, did you reboot your machine? It's not a good way to resolve the issue since you aren't finding the root cause of the issue. Finding the root cause of the symptom is the On Leeway toe actually resolve the issue permanently, and this requires digging in and spending some time on the issue. Once the actual root cause is found, I now figure out how to fix it. So no matter how minor that issue I like to write up a quick action plan that I'll follow. This does a couple of things first. I've documented what I plan to do, so if I have tow hand off the issue to someone else, they have something to go on. Second, if it does not work and I need to back out, I know the exact steps that were reformed. Before implementing anything, I review my plan to make sure I'm addressing the root cause for a minor software update to ah complete system rebuild. I always, at least right a quick plan to follow. Then I step back for a moment, and I consider whether this plan will address the root cause and therefore resolved the symptoms. If so, I implement the plan and verify that the symptom is gone. If it isn't, you may have to go back to the beginning. Or perhaps you had a couple of plans so you can go back and try another one. Quick note on applying solutions. Always apply one solution and evaluate if you apply more than one fix at a time, like restarting a service, restarting your Web browser and then rebooting your machine to fix an internet application issue. You don't know which one. Resolve the issue, stick with one, apply IT, verify it, and document and PowerShell can help us through all of these stages, from gathering information to fixing issues.

Gathering Information with PowerShell

[Autogenerated] So in the demos today, I'm going to walk through a number of scenarios that fall into these categories, as you see here. Computer and hardware networking and files and folders. While this does not cover the entire spectrum of things that you can do within your environment, it does cover a great percentage of areas that you often run into, and it'll show you techniques that you can use in any of the other areas that you're looking into. So before we get started, I just wanted to do a quick reminder of the method that I'll be using throughout many of the demos we talked about this previously for the demo are most likely use. Get Dash Command to find the command I'm looking for. Then I'll move to using help with the dash examples parameter to see how to use the commands I'm working with. And when I want to pull a specific piece of information from an object, I'll use Git Dash member to view the available properties I can pull from the output of the command. Most of the commands I'll be using involved the get dash verb with get dash you confined information about a lot of things. Users file folders, printers, local computers, processing services, network information, thousands of different pieces of information that could be used to help find a solution for issues.

Demo: Finding Your Way in PowerShell

[Autogenerated] So with that, I want to do a quick demo off finding your way in power shell. And this is just a demo walking again through the methodology of using Get dash command, get dash help and get Dash member toe. Find the commands and we're looking for for a specific issue and using those the find the information we're looking for. Let's walk through a basic troubleshooting scenario. So let's say a user calls us up and they've just been given permissions to be able to remote connect into another computer on your network, and that has been set up using remote desktop or Rdp. And they call in and they say they try to connect and they're not able to connect. So there's a number of things that could be wrong here. The policy could have got set up improperly, they don't have the right permissions, or the firewall on the remote system might not be set up properly. Any of those trees could be areas that we could take a look at. So first thing I'm gonna do is I wanna take a look at I think maybe the firewall could be the issue here. So the first thing I'm gonna do is I'm gonna use get dash Command and I'm going to do a search based on queer ing just for the word fire to find commands that are related to that. So we see we get a huge list of commands. So I want Thio refine this down so that I'm just looking for the get dash. So the get verbs. So I'm gonna change this. So my query is get dash and then wildcard renting fire there to see what I get. So now we get, um, or refined list with all the get dash commands for the Net firewall commands that we have. Another way I could have done that is that I could have done a get dash net firewall with a wild card at the end again, getting the same results here just different ways of going through that query process. So now that I have this list, I have a pretty good idea that the get dash net firewall rule is the command that I'm looking for. So what I'm gonna do is I'm gonna type in help to find out more information about the get dash net firewall rule So we see we've got our son tax. UI says it retrieves firewall rules from the target computer. So bingo. That's exactly what I want to use. So at this point, I do a couple of things. Chances are we'd run the command and UI pipe that into get Dash Member because we want to see what are the properties that are available toe work with. So we see we've got a number of properties that we can look at in here. Another way that I like to use a swell is I like to simply run the command to see what happens to see what the output is for us. So when we run this and this is going to take a while to run because there are a lot of firewall rules on this system, So now that that's finished in our list here we see, we have a number of different pieces of information that probably would be helpful for us, depending on what the type of query is that we're looking for. So we know that we're looking for something dealing with remote. So what I'm gonna do is I'm going to do a get dash net firewall rule put in for the dash name parameter. Look for a name of a rule that includes the word remote. So notice that it brings back a number of rules here. Number of remote desktop rules. And we see that we also have some remote task. So I wanna further refine this down to looking for just remote desktop in the name. And so when we run that, we see that. Okay, Now we have some items here, and now I'm gonna put this into format dash table, because that's going to give me a better view of how to look at this. So Okay, there we go. So we see we have five rules and we see okay in the fourth column, all of these air set to false. So okay, the firewall set to false for these so remote desktop isn't allowed through the firewall. So at this point, we could let a senior person No. Hey, they need to modify the firewall. Or if we have the ability to do that, we could actually do that with power show, and I'm gonna show you how to do that. So we take the same command that we have to get dash net firewall rule. And if we wanted to enable all of these rules, we could pipe that into the set dash net fire while rule adding in the dash enabled of true parameter. So what it's gonna do is it's going to take for each one of those rules. It's going to set each one of those rules so that enabled is set to true on their notice. At the end, I put in a dash. What if what that does is it actually doesn't run the command? It will verify that the command is properly formatted and it will run IT air quotes. However, it will not actually perform the action. So if we see it tells us, what would it have actually done? So it tells us that it would actually have set the rules on those two, whatever we wanted there. And if we go and we run that command again, what we'll see is will see that they're still set the falls. So that's how you go through a basic troubleshooting methodology using power shell

Gathering Operating System Information

[Autogenerated] when we're going through the process of gathering information about an operating system and the underlying hardware for that local remote system, we can use a number of different tools. The first tool we have is Windows management instrumentation or W. M. I, which is an extension in Windows Os W. My was built by Microsoft to allow access to information contained within the operating system. It's based on the Common information model, an open standard that defines how managed elements in the 19 environment are represented as a common set of objects as well as the relationship between them. Sim was introduced in PowerShell version three toe work with Windows Management instrumentation prior to version three of Power Shell. You only had access via the W. M. I command. Let's version three introduced us to the SIM Command. Let's so generally they provide us both the same information. So which you use depends on the version of Power shell you're running. If you're running Prevert version three, such as Windows seven or 2000 and eight are-two, you can continue using the legacy W M I command. Let's Otherwise, the Sim commandments are the way to go as the W. My commands are now legacy in the Microsoft world, and there's not any future development that's being done on them. So when we're accessing W my information, we access the W. My repository. Within the repository, there are a number of name spaces. The SIM V two is the name space. It contains the classes that were looking for the classes air the things like Win 32 underscore processor that contained the information we're looking for, like device ID and name for our processors. This information is stored his properties that are accessible from the objects output by the command. So let's take a look at W. My and Symon action and look how we use those to gather information about a local computer.

Demo: Gathering Computer Information

[Autogenerated] in this demo, I'm going to be gathering information about a user's computer using W oh, my and Sim. So you can see how we can use power shell to start gathering information for troubleshooting and end system. So let's jump into our demo. In this demo, we're gonna use power shell toe access, the performance counters that are on a system. So just like you would be able to do through the gooey using performance monitor, we can access those counters and the counter data using power shell. So first we want to figure out what the command is that we're actually using. So I'm gonna put in, get Dash Command, and I'm gonna look for the key word counter and you'll see it'll bring back a number of commands for me. I'm guessing get dash counters the one I want because the other ones are related mawr to storage and two databases. So we're gonna do a help get dash counter, and as we can see that this does get the information for riel time performance counter. So it's this is the command lit we're looking for. At this point, I'm gonna put in, get dash counter to simply see what this brings back for me. So when I run this, it's gonna bring back six of the default counters that you would find in performance monitor some networks and processor memory and physical disk. So we see we have memories. Percent committed bites in use here. That is an important counter. But let's say we want to get into some other memory counter, so let's dive deep into this. So I'm gonna use my search method here. I'm gonna do get dash counter and I'm gonna access a parameter called list set. And I'm gonna look for list sets and include memory. So what this does is this is gonna bring back for me all of the counter sets where their names include memory in it. So you see, here I have one related to just memory, and that's the one that we're actually looking for. So I'm gonna go ahead and do a get dash counter, and I'm gonna call specifically the memory list set and you see there it brings back my the memory list set and you'll see underneath. It has a counter, and it has a list of all of the counters. Notice that it doesn't have every one of them because it's been truncated. So I want to see what all of the counters are that are available for this one. So what I'm gonna do is I'm gonna take that same command, and I'm gonna pipe it into select ash object. And I'm using a parameter called dash expand. And what dash expand is going to do is it's gonna expand that counter so that I see all of the names of the counters that are in there. So you see, there we go. We have a big list of all of the counters that are available for us. So now I want to take a look at the percentage committed bites and use and also the pages per second, because it's oftentimes a good idea to look to see if ah, system is paging out. So go ahead and type in my command. And there we go. So there we see the number of pages per second and the percentage of committed bites in use for the memory. So that's a quick and easy way for you to be able to take a look at the performance counters on a Windows system

Demo: Using WMI and CIM Information

[Autogenerated] Now let's take a look. A memory information using W Oh, my and Sim. So I'm gonna put in get dash W my object dash list and a wild card. What that's going to do is it's gonna bring back the list of all of the W M I objects, all of the class names and classes that I can work with. So, you see, this is a pretty huge list of things to go through. So if I go here, notice if I do get Dash Sim class and I called dash class name with the same wildcard and we run this, you see, we get another long list that includes all of the classes and class names that we can work with, what we're kind of showing you here is that both w oh my and Sim access the similar pieces of information on computer systems. It's just w my was the legacy version, and Sim is what we're using for things as we move forward. Soto, look at memory specifically, I'm going to do a get dash sim class and I'm gonna call the class name without search parameter of memory. So you see, it brings back all of the different items that I have for memory. You'll notice that there's ones that are win 32 underscore physical memory, and there's also a SIM underscore physical memory. These are basically the same pieces of information one simply using 1 32 and w my. The other is simply using Sim. So what I want to do is I wanna call out one of those objects so I'm going to use Get Dash W my object calling the class Win 32 underscore physical memory. So you see, it brings back all of my physical memory information for me. Now let's see that if we used to get Dash Sim instance using a dash class name of that same win, 32 underscore physical memory. And as you can see, it brings back basically the same information about the physical memory. Now I want to see this information in a little bit. Compact format. There's a lot of information here, and I'm really only interested in the capacity you'll notice there's a tag physical memory one and a tag physical memory. Zero. That means there's two pieces of memory in the system. So to see both of those I could do a get dash Sim instance, calling that same win 32 underscore physical memory. And then I'm gonna use select dash object to just pull the tag and the capacity. And there we go. So we have a nice list. Shows us the physical memory that's on a system, the capacity for each of those pieces of memory. So that's how we would search for things using SIM and W M. I.

Demo: Working with Network Information

[Autogenerated] Now let's take a look at some common network troubleshooting. And so now let's take a look at some network troubleshooting some other activities we could do from the networking side. So one of the things with Power Shell is that Windows Power Shell does support some of the legacy command. So if I you put in I p config, which were used to using in the command prompt UI see, it brings back the the I P. Config information by the U. N I. P. Config slash All we see it brings back all of the information. What's important to know about this is if I pipe in i p config into get Dash Member notice, there's no properties that are related to it. There's a property of length, but basically what this is doing is it's showing me that even though I could run those commands, they're not true power shell commands. So they're not sending the data over as objects that we-can work with each of the values that are in there. So in order to be ableto work with the individual values, we need to be using power shell commands for that. So we're going to use our process again. We're gonna look for get dash commands that start with get dash net I peep And when we run that we see we get a number of commands that are related to that. So the top to get net i p address and get net I p configuration are the ones that we're gonna look for. So we'll type in get dash Net I p address and we'll see that That brings back the I p address information for all of the adapters that I have in my system. If I do a get dash type configuration, you'll see it will bring back the I P configuration for the Ethernet address You. So you get a i P V four address. If there r i p v six Gateway, that would be there. We have our d n A server, Aziz. Well, that's being used for the adapter here, So both of those will give us information that will allow us to do troubleshooting for networking. So the next thing what we wanna do is we want to take a look at some of the DNS information. So I wanna find the commands using GCM, which is the short alias. Forget Dash Command looking for get commands related to D. N s. So you bring See, it brings back a bunch of DNS server commands those air all from the are sat the remote server administration tools that we installed the ones that were looking for the DNS client ones that are based for the client machine. So we're gonna refined this down to just bring us back the list off the DNAs client command. So we see we have our DNA's client commands here. So I'm just going to do a get dash DNA's client and you'll see that that brings back the DNA's client information for the interfaces on my system. And it will show underneath the connection specific Suffolk's what the DNA Suffolk's is for that adapter. What it's gonna USA's part of its ah, resolving of addresses. If I want to see what's in my DNS cache, I can use a get dodged ness client Cash haven't gone out anywhere, so I didn't have any data in there. If I do a get dashed DNA's client server address, this will tell me what the DNA server is for all of my adapters. So what are the adapters using as a DNS server to resolve DNS name. So this is a common troubleshooting one where perhaps a client is having a problem getting to a website. You often want to check What server are they're using to revolve resolved names? Names. Next, we'll take a look at how can we map a network drive, which is a common procedure. So network drives use S and B the simple message block. And so I'm gonna look for the commands that all include SMB. So you see, there's a number of commands here related Thio SNB. So I'm guessing that the command is related to SMB mapping. So we see we have a get dash s and B mapping a new and remove so we can get information about the current mapping. We can also create a new one. We can also remove mapping is that we have. So if I do a help new dash s and B mapping and look at the examples, it's going to give me the examples of how to create a map drive using this command. So let's go ahead and create that. So I'm going to do you new U. S and D mapping. I'm going to set a local path with the drive letter W. And I'm going to a remote path using the U. N. C path off wack wack D c 01 wax share and you see Okay, now that that's connected to that, if I do a get dash s and B mapping, it will show me that that map drive is on my system. I want to connect to that. I could do a CD, which is basically a change directory. I can change to the W drive. And then if I do a directory listing there, you see, it lists all of the directories that are available there. So that's a number of different things that you can do from the networking side with power Shell.

Demo: Reviewing Event Log Information

[Autogenerated] the next piece of information I want to take a look at is I want to take a look at the last time a system went through a reboot because this is one of those things that Yeah, well, tell users that you need to reboot your system because it is one of those things that will commonly fix issues, though we don't want to use that as the root cause. But it's nice to know when the last time a system went through the reboot process and the easiest way to do this is using event, viewer and toe look for ah system Event-Hubs in 74. And so what this event signifies, IT signifies that the system went through a reboot process. So let's see what we confined in power shell. So I'm going to put in get dash Command, and I'm going to search Forget dash commands that include the word event. And as you can see, we get a number of ones that are related to events here, and in this case, we wanna look at the get dash event log because we want to get the entire logs, so we're gonna do a help, get dash event log just to verify. And then we'll do the dash examples so that we know how to use this. So we see that this is gonna go get us the event logs and list those out for us for local and remote computers. And we see that if we use get dash event log dash list that's gonna list the events logs available on a computer. So we're gonna go ahead and type in. After our examples, we're gonna do a get dash event log. I'm going to call the log name of system, and then I'm gonna pipe that into get dash memory. So you see that this has a ton off properties that are related to all of the different types of entries that are in the system log. So you'll think, See, like category names, category numbers. You'll see it down at the bottom. There's an event I d and that event ideas what we're looking forward to match here. So what we're gonna do is we're gonna type in, get dash event log. We're gonna call that system log, we're gonna look for the newest 1000 events, so it's only gonna get the last 1000 events. Then what we're gonna do is we're gonna do you use aware dash object, and I'm gonna look for the event I d. That's equal to 10. 74. So you notice I'm doing something a little bit different here? Notice I've got my curly braces and inside there, I've got a dollar underscore dot event I d and what this is doing, This allows me to access dollar underscore, accesses the current object in the pipeline. So what it's going to allow me to do is by going dot event i d. It's basically telling power Shell. Hey, I wanna look for the property event I d. That's in the current object coming through the pipeline and only pull out the ones that are equal to 10 74. So once I do that, I'm gonna then format table that where I get the machine name, the username and the time generated. And so we come back and there we go. We see that CLI no one. We see that the user names that were involved with the reboots and we see that the times that were generated that the times those air went through the reboot. So that's an easy way for us toe work with event viewer to get that reboot time. And we could use that for any type of event, so we would have an event viewer.

Demo: Using Get-ComputerInfor

[Autogenerated] in the next demo, we're going to take a look at another option for gathering system information, and that's called get dash computer info. So get dash computer info was a command that was added into power shell recently That allows you to be able to gather, ah, large amount of computer information about a system this basically brings in tow one command. Ah, lot of the different things that we would usually use. W oh Meier's sim to gather so many of the things that we did in the last demo UI Congar other through this single command. So this demo is gonna focus on using that command and how we can better get to the information that's contained with IT. So let's jump into our demo. So just like everything else, we're gonna run help get dash computer info, and it's gonna bring back the help file so you'll notice in the Sun tax. Here there's Onley, two parameters of property and then common parameters. What's important to know about this is that we can't use the parameter dash computer name toe accesses for remote system, so it has to be run on the local system when we get into the remote ING module. I'll show you a little trick of how to get around this and be able to use this remotely. But for this instance, or just simply sitting on the local system and what we're gonna do is we're going to take a look at the examples for this, and it will give us examples of how we can use it. So if we do get dash computer info, that's going to give us all of the information on the system. So we'll go ahead and run that and pipe that into more. It's going through and processing. And it's pulling in all of these different pieces of information that we can use so we can see. We've got to know s name in there. So operating system information. Ah, ton of information that we can use and gather from a system. So let's say we want to see just the memory information. So I'm gonna use get dash computer and the property of memory, and it will bring back for me all of the information that has on memory. So total physical memory, total visible memory, virtual memory. So a lot of pieces of information there, so this is a really cool built in tool that will allow you to grab a lot of information that's available about a computer.

Demo: Working with Files and Folders in PowerShell

[Autogenerated] for most administrators, working with files and folders is a common everyday tasks. So I'm going to show you how to use power shell toe work through many of these day to day tasks. So let's say you're looking for a file for a user that's stored on a network drive, but you don't know where they stored IT or what the name of it is. All you know is the type of file that's not a problem for Power Shell. So the command we're gonna use for this is get dash child items. So let's take a look at the help. Forget Josh. Child item. This is basically a command that gets files and folders in ah file system drive. So let's take a look at when we run. Get dash child item against that map drive that we created previously, and we use a dash re curse so that it goes through all the directories. So as you can see, it's going through all the directories. There's a bunch of files located out there. That's a lot of stuff to go through. So now what we can do is we put in get dash child item, same path or re cursing through here, we use get Dash Member to see the properties of the objects coming through. So you'll notice that there's an extension property Bingo, because what we wanna do is we want to find all of the dot PNG files that have that as an extension. So what we can do is we can do a get dash child item again. We'll go through that path and then we're gonna use where dash object to find the extension that's equal to dot PNG. So notice now it brings back just the files that end in PNG. To get a better view of this, we're gonna run this command again. We're gonna use where dash object Thio get all the PNG s, and then we're gonna put it into a format table where we're only looking for the directory, the name of the file and the last write time. So there you go. So now we have a listing of all of the PNG files that are on the W drive by the folder and the time that they were created so that we can use that to help our user find their file. So the next thing is, sometimes we wanna work with moving piles with power shell. And we can absolutely do that. We can move a large number of files very quickly, So I'm going to use get Dash Command to find the copy commands so we'll see that we have one called copy dash item, and that's the one that we're gonna use. So we'll look at the examples for copy dash item, and we'll see that this allows us to copy a file to a specific directory So we'll go ahead and run this command. I'm going to copy dash item copying from the W drive to the destination off C colon slash copied folder. I'm going to re curse through that directory and use verbose. So what that's going to do is it's going to grab all of the files and the directories that are in that location, and it's also gonna verbose. It's gonna tell me what it's doing as it's going through. So you're gonna see there is a bunch of yellow basically those air, the verbose messages telling us what's happening. We're performing an operation to copy a file from the target location to the destination location now if we do a directory in that folder we just created and re cursed through that we see very similar to when we did the directory on the W drive. So it looks like all of our files and folders were copied over. Now, if I want to move this directory to another directory, I could do move dash item. So I specify the source and then the dash destination parameter A. Moving that to a folder called Move Folder. And we're doing verbose again because it's on Lee moving a single item, which is a folder. We just have one entry there by do a directory listing on Move folder. Well, see, there we go. We see all of those items were moved over. The next thing we want to take a look at is renaming an item. So let's say I want to rename that folder the move folder and I want to call it renamed Folder. So you see the dash new name parameter that allows me to do that. And then if I do a directory in the C drive UI See, there we go. So we have that renamed Boulder, and that's how you use power shell to work through the file system

Wrap Up

[Autogenerated] So we covered a ton of information, some great troubleshooting and information gathering stuff. So ah, lot of these commands you can use in your day to day environment. When troubleshooting issues as you're beginning working on issues, you want to make sure that you have a good repeatable methodology for troubleshooting. This is key to being a successful I T. Pros. Using our friends, get dash, help, get dash command and get Dash Member will help you find everything you need within power Shell. Armed with these and a curiosity to solve problems, you'll be ready to take on most problems in your environment. So that wraps up gathering information with Power Shell in the next module. I'll show you how to get started using power show against remote systems because that's really where all these commands will come together and become extremely useful. So we'll see you in the next module.

Remoting with PowerShell

What We'll Cover

[Autogenerated] knowing how to find information on a local machine is fine if you have access to the physical machine in this day and age, much of our troubleshooting and problem resolution happens remotely, so we may never touch an end user's computer or a server in person. Because of this change, remote management is a key skill practice in almost every environment. So knowing how to use power gel remotely is a key to your success. And that's what this module is about promoting with power show. So in this module, I'm going to cover the basics of re moting and how it works in Power Shell. With the latest versions of Windows, Microsoft has made remote management a key feature, and power shell is no exception. We-can even use power shell to remotely connect from Windows or from Linux or Mac systems. Two other systems running power shell. Next, I'll discuss how to enable remote management if it isn't already enabled on the system by default. Windows clients don't have power Shell Ri moting turned on, which is a good thing, so I'll show you how to enable that on the client system. I'll give you a brief introduction to variables and using them in power shell. These become mawr helpful as you move into repetitive tasks and scripting. There are a great way for us to store information that we use over and over again and last and definitely not least, ah cover multiple methods for connecting two remote systems and demonstrate how to perform each method to administer your remote systems. So let's dive into power Shell Ri moting.

Running Remote Commands with PowerShell

[Autogenerated] PowerShell has a few options for re moting, Windows Management Infrastructure or W. My is an option for both Windows Power Shell and Power Shell Corps for finding information on a remote system. Another is Windows Remote management Win RM. This is the Microsoft implementation of the web services for Management Protocol, or WS Man, which allows users to run power shell commands on remote computers. This is available in both Windows Power showing PowerShell seven, and this is traditionally what's referred to as Power Shell Ri Moting and a newcomer to the power shell world. Though it's been used for years, and the Linux and Eunuchs realms is SSH power Shell course supports the use of SSH for connecting toe windows and non Windows computers. It does require additional installation and configuration to use, so we'll focus on using the built in connective ity tools like Ws Man and W. M. I. For our demos and last is RPC, which is used when we're utilizing the computer named Parameter. And it's on Lee, available in Windows Power Shell and not Power Shell Corps

Enable PowerShell Remoting on Windows PowerShell

[Autogenerated] in order to remote into a client using Windows Power Shell, you need tohave the Wright permissions along with having the client enabled for power shell remote ing to enable power shell Ri moting you need to run the enable ps remote ing on the target computer. This performs a number of tasks like starting the session listener and configuring the Windows firewall for remote ing. Next, you need to give the user access to power shall re moting using the set Dash P s Session configuration command. This allows you to modify the session permissions and this will allow the remote connection toe happen for power Shell corps. You need to set up the remote system to be an endpoint for power shell connections. This is done by installing a script located in the PS Home Directory. You need to run installed dash PowerShell remote ing dot ps one as administrator on that remote system and also make sure that your user has the proper permissions to perform whatever task they're looking to do.

Demo: Requirements for Remoting with PowerShell

[Autogenerated] in this demo, I'm going to cover the configuration steps needed for remote ing with Windows, Power Shell and Power Shell Corps. I'm in the PowerShell console on my administrative work station and I want to just test my connective ity going over to my client to machine. We'll do a git dash service against that computer client 02 and we'll wait to see what the reply is. You notice this comes back and error. This operation might require other privileges, so that tells us were not being able to connect over there. I'm also going to try another command, get Dash P s session, which allows me to connect into a remote machine and just like the other command, this one aired out. So that tells me that there's an issue on the other side. So this error message goes into talking about that when RM can't complete the operation that there could be an issue with the network. You could take a look at the about for remote troubleshooting, which is a good reference for this sort of thing. But the real reason we're seeing these is because we need to configure client 02 So I wanted to show you those air messages. So you're familiar with them. So I'm gonna go over to my other machine on CLI. No, to the first thing we want to do is we want to enable the PS remote ing on this system. So I'm gonna do a PS promoting dash Force to get that set up and so that's gonna basically set up the win RM service, make sure that it's running at any firewall exceptions that need to be added in for win RM, so that should be good to go. The next thing what we need to do is we need to make some changes so that the local administrative groups have the helped US support group added into it. So I'm going to do that using set Dash P s session configuration and I'm going to put in the name Microsoft Power Shell and then I'm gonna show security descriptor you I so it's going to give me the gooey to be ableto work with that. So go ahead and add in that helped us group and we'll give them right and execute so that will give the local permission Sat for that the next thing. What we need to do is we need to make some changes to the firewall. So the first changes we need to make sure that the Windows management instrumentation or W on my ports are open on the firewall. This will allow us to connect for any legacy using W. M I. So we're using Get Dash that firewall rules to pull all the world. And then I'm using where Dash object to pull just the rules that match Windows management instrumentation is a display name, and then I'm piping that into set dash net firewall rule. And what it's doing is that setting enable on that rule the true. So it's turning those rules on when we run that you'll see that it'll go through and it'll enable a number of rules for us, and I'm going to do the same thing for the remote service management. So remote service management allows us toe work with services remotely on a system. So once those air all set up and then we go back to our other client, we should be able to connect into client a one from Client 02 back on CLI in. No one will type and get dash service. Connect to CLI in 02 and you see that pulls up all of our services. So let's try toe enter PS Session Command that we put in before to get into our client 02 and we see that it connects into that client. If I do a command on there, you see that it's running that on the remote system. So that gets us all set up and ready to go. And now we can remotely manage client or to the one thing you need to remember about. This is in most organizations, all of these permissions and things will be set up for you. Bye. Your systems administrators. So that'll be either pulled, pushed up, a group policy or some other means for that. So that's setting up your systems for remote management.

Working with Variables

[Autogenerated] When you're performing a lot of commands from the console or working with scripts, you often have cases where you need to re use information, retyping the name of a computer. Multiple times can become a pain, and that's where variables come in. One of the things that I shoot for when working in the console is using as few keystrokes as possible for efficiency. Variables are a component and power shell that allows us to become mawr efficient. Basically, ah, variables a container for information that we wish to reuse, such as an energy ah, string or even the output from a command using the dollar sign, followed by a unique name of your choosing. You can create a temporary variable to use while you're in the council or in a script. When you need to use the information in the variable, you simply call it by entering the variable in the console or script

Demo: Working with Variables

[Autogenerated] in this demo, I'll show you the use of variables in the console. I'll be focusing on showing you the built in variables and power shell and how to create your own within the console in the next module, I'll show you how to use the variables in a script. Let's dive in tow, working with variables The first thing I want to do with power shows. I want to take a look at the built in environment variables that are built into windows and how we do that through power Shell. What we do is we issue a get dash child item command, UI access thes E N V or the environment PS drive and I'm piping that into Mawr. So this shows us all of the environmental variables that we can use. So if we go ahead and type in dollar envy colon computer name so any of those names you see in the list you can put in that after dollar envy colon toe access, those we see that gets us the computer name. So that's a quick and easy way of getting the name of the local system that you're on. So the next thing what we want to do is we wanna look at the variables that are currently available in the console. And so these air power shall specific not necessarily built into windows because the ones we just showed you those air built into windows and available anywhere, whether it be through the gooey through the command prompt what have you these air specifically available inside a power shell? So you see a number of variables that are able for you to be able to use within power shell. So I'm gonna go ahead and issue the dollar PS version table, and that shows us the version of Power Shell that we're running on our system. So now what we want to do is we want to set up some Varios holds because variables are a great way for us to store piece of information to be used later when we're running commands or in scripts. So I'm going to create a variable called dollar computer name, and I'm gonna make it equal to client client, too. Then I'm gonna simply call that variable by typing in the variable, and we see it brings back client are-two. So I know that that's stored inside of the computer named Variable. So now if I do a right dash output, I'm simply putting a message in here where I'm including the variable in IT. So notice I have double quotes here. So what's gonna happen, you can see from here is it brings that value into the message. So the name of the remote computer is client to-be. So it's not putting in the variable. So any time you use double-click quotes in power shell and you're using a variable, the value of the variable will come through for you. Now if we try doing a right dash output a similar message. But this time, what I'm doing is I'm using single quotes. So when we do this, we see that what comes through in the message is the name of the variable. So when you use single quotes, it will bring back the literal meaning exactly what you put in there. So if you want the variable name to come through you single quotes, if you want the value of the variable to come through, you would use double-click oats. So now what we're gonna do is we're gonna store credential inside of a variable. And this is a really common tool for you to use, especially when you're running a script and you want to run it with an elevated credential. So we're taking the variable, and we're simply putting a command in IT. The git dash credential Command notice it brings up the windows You I'd box. I'm gonna put in my credentials, put in my password and then when I call that variable, you see that it brings back the username and then the password a system dot security dot secure string. So that tells me that I've securely store the password, so it's not stored in clear text. So this isn't a security loophole that you need to worry about. And now let's see adding a credential in power Shell corps. So I'm going to type and get dash credential and notice nothing's there. So that also shows me that my variables that are stored in one shell don't pass over to the other. So it's simply there in different scopes. So I need to create a credential over here, so I'm gonna call dollar cred annual type and get dash credential and notice it doesn't bring a U. I because it is PowerShell cornets using the dot net core framework. It's keeping it all within the console for us. So I'm gonna put in company slash and be admin put in my password. And if I call that variable, you see that it has that in there. So that's how you would do that in power shell course. Basically the same process just a little bit different as far-as how it looks within the console. So now let's go back to Windows Power Shell and we'll look at variables in action. So back in Windows Power Shell, I'm gonna do a get dash variable and called the name for the variables to begin with c to verify that. Yep, the variables that I created are in there. So now what I want to do is I want to use the get dash service, and I'm putting in the variable for the value for the computer named parameter, and we'll see what happens. So there it goes, So it shows you how we use that variable to be able to run a command

Option for Remoting with PowerShell

[Autogenerated] So now you should be ready to learn about different options for remote ing. Many Windows power Shell commands have the computer named parameter that enables you to collect data and change settings on one arm or remote computers. These commands use varying communication protocols and work on all Windows operating systems without any special configurations. Next are set of commands using the DASH P s session noun. These allows to create, enter and remove power shall remote sessions. With enter Dash P s session, you actually begin running your console prompt as if it's on the remote machine. This is great. If you want to run commands real time against a remote machine as if you're on it, then we have invoked command. This allows you to run a script block against a remote system. A script block is simply a block of power shell commands. This is often used when you want to gather data in a script or you want to use the output from commands for other purposes. This is also a great way to run command based on tooling you don't have installed on your system. As the commands run on the target system, one note is that power shall remote ing with invoked ash. Command uses XML to transfer data. The target will serialize the results into XML and transport the output back to the initiating system. That data is then d serialized back into objects that you can use in the pipeline. And when those are placed in the pipeline, you may lose something such as methods. But generally you won't lose any of the information that you're looking for and last is new dash sin. Typically, when we use SIM command, let's they use ws man by default. This is great. When we're on computers running version three of power Scheller greater. I found that some commands, like get dash s and B mapping don't support the computer named parameter, so you can use new dash sim to get around using this to connect to remote systems.

Demo: Remoting with PowerShell

[Autogenerated] Now that you know, a bunch of different remote ING Technologies will set into the next demos where I'll cover all of the remote ing scenarios we've discussed and show you power shall re moting in action. The first re moting technique we're going to run through is using the computer named parameter. Remember, this is gonna be one that's gonna be supported in Windows Power Shell on Lee. And you may want to experiment with this just to verify that the computer named parameters available for the commands that you're working with. So I'm going to create a variable for computer name that we're gonna use throughout this, And I'm just gonna use a get dash service command and we see that that goes ahead and that runs by adding in that variable into the command. Now, the next promoting we're going to take a look at is using the Dash P s session command. So I'm going to do a get dash command and look for the command that have PS session as a noun in IT. We'll see we get a number off commands coming back, so we're gonna start out by using the new dash p s session, which allows us to create a new session. So to start that off, I want to create a credential that's going to be used for this and we'll do that Same technique we showed you before. Get dash credential Put in my credentials to-be stored in that variable to be used for my connection. Now we'll put in our command new Dash P s session. I'm calling the computer named Parameter, using my computer named Variable and calling the credential parameter and using my credential variable and we see that it's created a session for us. So now toe connect into that remote machine. I simply doing enter PS session and then I call the name of that session. In this case, it's called Win RM. One and you'll see that the prompt exchanged the CLI no to and from here by doing e n v computer name. We see that we are on CLI in 02 to get out of this session and go back to CLI no one. I just simply type in exit and that brings me back to their I do a get Dash P s session. It'll list all of my sessions for me. I can also enter that, using the idea of the session as well. So if I put in a parameter for I'd I can put in one and we see it enters into that just verifying that we are on the same system over there. It's bringing back the names, so that shows us how we can connect They're using Enter Dash P s session. Now, if I want to remove that session, what I can do is I can do a remove Dash P s session and we'll put in the idea of one enter again. And if I do a get Dash P s session, we see that we don't have any PS sessions. So that's a great way for being able to connect to remote systems if we wanted to Riel Time command running on a remote system because, as you saw our prompt was basically running the command on that remote system. Next, we're gonna look at running commands on a remote system using invoked ash command

Demo: Remoting with Invoke-Command

[Autogenerated] first thing we want to do is we want to take a look at the help file for invoked Ash Command. So Thio help invoked Ash Command, and it shows me that this runs commands on local and remote computers. It gives me the cent tax, the description I could look at the examples of how to use it. So next I'm going to send my variables up. So I'm set in my computer name variable to client, too. And then I'm gonna set my credential using the GATT dash credential So we'll go ahead and put our credentials in there, and then we're going to do an invoked ash command. I'm gonna call the computer named Variable with the computer named Parameter. I'm going to call the credential with the credential variable. And then I'm gonna put inside a script block. So the script block parameter is going to specify what do you want to run on that remote system? So this could be a single one liner. It could be a script, really, whatever you want it to be. So we put that inside the curly braces. So you noticed we're doing get dash service dash computer name and calling the computer named parameter notice that comes back with an error cannot validate the argument of the parameter computer name. The reason for this is we've defined the computer named Variable on the system we're on on CLI No. One. That variable doesn't pass over to CLI in, 02 because what the scripture running is running on that remote system. So there's a little trick that we-can Dio is we-can modify the code a little bit to allow us to pass variables into a script block that's running on a remote system. And it's called using. So we make a minor change to our variable, so you'll notice that it's get that service. The computer named Parameter and Dollar using colon and then the name of the variable computer name has been added. So by using dollar using colon that will allow you to use any variables that are on your local system and pass those through to a script block that's running on a remote system. So when I go ahead and run this, you see that it runs that command the way I wanted it to. So now let's say I want to put that into a variable to capture this output so I can simply create a variable called data. And then I'm gonna put that entire command that I just ran in there. And once we get that all typed in IT runs and UI pipe that into get dash member, you see that it passes back for us the objects, and it shows the properties in there. So you notice that all of the properties air there that we would normally have their the number of methods have been cut down just based on that whole process off the data being serialized and d serializing through the process. So it really doesn't have an impact on the data, the properties that we're looking for, it does change. What we could do is far-as the methods. So that's how you would use invoke command to be able to run command against the remote system. Now, if we want to see this running on PowerShell seven, let's open up our shell seven got-to. Go ahead and put a command in here. Invoke Dash Command computer named D. C. 01 for the credential. Get dash credential in the script block notice. I'm doing a get Dash 80 User dash identity Felix be piping that into format dash list. So when I run this, it's gonna ask me for the user put in the my user here and notice that brought back all of the information about Felix Bender in relation to their active director user. What this allows you to do is not only am I running a remote command against remote system, this actually allows me to be ableto access commands that aren't installed on my machine. So let's say you're running from a Linux or a Windows workstation that doesn't have the active directory command. Let's I could simply use invoked ash command toe access a computer in this case D c 01 that has those commands installed. It has the 80 module on IT, and I can run the command against that system, and it will allow me to be able to use those tools that are installed on the remote system. So this is another cool way that you can use power shell to be able to remote into a system. And those are the different ways we could use invoked ash command

Demo: Remoting with New-CimSession

[Autogenerated] and the last remote ing technique we're going to show you is how to use new dash sim session. So I want to first create my variables. So I'm creating a variable for computer named CLI No to. And then I'm also creating my credential variable as well. We'll put in my credentials once those air in. I'm gonna issue a help command against new Dash Sim session so we can take a look at the help for this. So this creates a SIM session for us that we can use with commands that support the common information model session. So I'm going to create a variable called SIM session and inside that I am going to store this new SIM session that I'm creating. So you notice I'm doing new sim session computer named Parameter. I'm using the computer named variable Credential parameter. I'm using the credential variable. So that goes ahead. And that stores that inside there. If I call that variable, you see that it brings back the sim session in the information about that sim session. So now if I do a get dash Sim session, it shows me all the SIM sessions I have now let's see using a SIM session in action. So in the past, I've noticed that a command get dash DNS. Client server address doesn't have a computer named Parameters. So let's take a look at the help. Forget Dash DNS. Client server address. So we'll notice in the center tax here that it does support sim session. So I'm going to try running this with the SIM session to see if it works for me. So well, type in the command type in dash sim session, put in the variable for the SIM session, and we see that there we go. It brings back all of the DNs client server address information on our remote system, and that's working with SIM session.

Wrap Up

[Autogenerated] whether information is located on a local machine or a remote computer, You now have all the skills you need to gather information wherever it's located. Remember Power Shell Ri Moting is based on W S management, and this allows you to be able to remote into any systems running Windows Power Shell or Power Shell corps. You'll need to make sure that you have all of the requirements for remote and configured on those systems, whether it be Windows Power Shell or Power Shell Corps. You may be able to do this, but it's often going to require administrative approval, so you may need to go to a senior person in your organization to make this happen to make working with frequently used inputs like computer names, I showed you how to use variables. Remember that variable is a way to store information you wanna work with, such as a string value with computer names, numbers or even the objects that you retrieved from commands. They're super useful and a necessary tool when you begin down the road of scripting and tool making. Last I walk you through the different types of removing. I'll have a specific purpose and usage entered ash. PS session is great for real time work Invoked Ash Command is great for scripting and new dash Sim session works great for legacy machines. I'm sure you'll find opportunities to use them all at one time or another. That wraps up this module on promoting with Power Shell in the next module. I'll introduce you to the world of scripting, and you'll see how you can put all the information you've learned into a nice, clean script for gathering information. With that, I'll see you in the next module building a user inventory script with Power Shell.

Building a User Inventory Script with PowerShell

What We'll Cover

[Autogenerated] in this module. The hope is to give you a basic understanding of what scripts are and how to run them. I'll cover the basics of the parameter eyes script. This is a script that takes parameters just like the command, let's and functions you've seen in previous modules. I'll cover the power, shall I. S C. The built in Windows tool for building and maintaining scripts as well as checking out visual studio code. Ah, multi platform code editor with many of the same features as the I S C. And much, much more. And the bulk of the module will be building a remote information gathering script. This will use many of the commands that you've learned throughout this course. I'll also show you some new techniques for working with objects and data. This will provide you enough information to start building your own simple scripts. So let's talk about scripts

Demo: Running Scripts in PowerShell

[Autogenerated] by default Power Shell does not allow the execution of scripts. This is by design for security reasons. So in this demo, I'm gonna walk you through setting up the council to run scripts using the set execution policy in power show. I'll show you how to modify and view the policy so that you can run scripts you need. So the first thing I'm gonna do is I'm gonna type in CD, and I'm gonna move to the directory that my scripts are located in. So now that I've moved into that directory, I want to issue the command to run the view. Dash stopped service dot ps one script that I have So I'll put that command in and we'll go ahead and try to run that. And as you can see, it comes back with an error that basically tells me it cannot be loaded because running script is disabled. So I need to modify the execution policy. So when we run, get dash execution policy, we see that it's that too restricted. Now, let's take a look at the help. So we're gonna do a help set dash execution policy, and I wanna look at the parameter off execution policy. And so as we take a look at that, it shows us this is the one that we use for changing the execution policies. So setting that new execution policy so it has all of the different options that we have restricted all signed remote signed bypass undefined. So we're gonna go ahead and change ours. We're going to set the execution policy so that it is remote signs. So what this means is that all scripts can be run if they're signed, if you've downloaded him from the internet or if you've created them locally on your system, so we'll go ahead and set that and then we'll go through and we'll try running that script again. And now we see it. It's gonna ask us for the host name, which tells us that the script is running. So that's how you go through the process for setting the execution policy, to allow you to run scripts so that could either be done locally or it could be pushed out by group policy by your administrators in your environment.

Demo: Using PowerShell ISE

[Autogenerated] as you may recall, the power shall I s C in the grated scripting environment is a built in tool for working with scripts and power shell. It's designed to allow you toe mawr easily building manager scripts. So let's take a look at the I S C and working with scripts. Now, back in our Edmund workstation, I'm going to go ahead and right-click my PowerShell icon. I'm gonna go run as I see Administrator. And then I'll open up Windows power shall I see as theon ministrations. So, you see, we have a terminal window. We have a commands window with the commands window. I could type in service here and find all of the commands related to service. And we see we have get dashed service. I could go a head and insert that, and that puts that right into the terminal. And Aiken issue that and that goes through and displays all of my services. If I click the little down arrow here that shows my scripting pain, I'm gonna go ahead and click the script Pain maximize. So it'll maximize that view. If I wanted to open up another script that I've been working on I can then goto file open. I'm gonna browse the location in my script Directory of my view, stopped service. Go ahead and open that. And that brings up all of the code for my script in the window. If I wanted to run this, I could simply choose the run script of the F five just like we did previously. And we see that runs if I go back to the window here. If I wanted to run just a segment of this, I could highlight IT. So let's say I made some changes to this and I wanted to simply run everything here. I could choose run selection or F eight and notice it does the same thing because I did highlight everything in here. So let's say I wanted to make a modification to this. I could put that modification in. I could click, save, click, run and we run our script. If I want to create a new script, I simply go up here, choose the new script. So now from here I could create a new script and let's say I wanted one that is going to use git Dash Sim Instance. I'm going to start out with a variable here for the computer name, and then I'm going to do a get dash Sim instance with Win 32 operating system. Now, if I put it in dash, IT starts giving me my whole list of all the parameters that I have so I could choose computer name. Then, as soon as I put in the dollar sign, it comes up with all of the variables that I've declared to this point. So IT notices that I created a computer named Variable so I can hit, enter, and that'll add that into my code. And then I could put a pipe here. And at this point, what I could do is I can hit, enter and go to the next line, and I could add in my next line of code, which is going to be select ash object with the properties off C s name and last boot up time. I'm gonna go ahead and close the command so we can see the full window here. So any time you have a pipe here, you could do a carriage return after that to continue that line going through. So at this point, I would simply save this. And we're just going to call this sim os info dot ps one not could go ahead and run that. It'll ask me for the name of the computer put in CLI No. Two. And there we go. That brings back our all of our information. So that's how you would use the I S. C to view a script and also to begin building a basic script.

Demo: Using Visual Studio Code

[Autogenerated] in this demo, I'm gonna walk you through installing and using visual studio code. This is a great new code editor that I highly recommend you take a look at for using on Windows and other platforms when you're working with power shell. So let's jump into using visual studio code. So in order to work with visual studio code, we need to download that so you go to code dot visual studio dot com slash download. It gives you the Windows Linux and also Mac versions for you to download so I could go down here and simply go to the download that I want to use. I'm going to download the user installed for 64 bit, and that will start the download process so we'll go ahead and click that off and run. That so visual studio code, as we said, is a multi platform tool for editing your code. So I'm gonna go choose next except the ULA next, next, next, and then we'll go install and let it go through the process for installing. So while that's installing, I'm going to go over to the website, and I'm going to click on extensions, extensions, air really? What? Make visual studio code amazing tool. So these extensions are basically add ends into code that bring in additional functionalities and features to your code So we'll go ahead and unchecked this so we can finish talking about extensions. So with extensions, these air very similar to the extensions that you would add into a browser and that these provide additional features. So we're gonna install what's called the power shell extension individual studio code. That brings a lot of the power of power shall in. So these extensions air either created by the community or their created by Microsoft or third-party vendors will create them. Aziz. Well, so we'll go ahead and close this out and then I'm gonna go ahead and go into my start menu. I choose visual studio code. So once this comes up, you'll notice that visual studio code uses a dark theme going to go ahead and close this. When it first comes up, you'll notice that it has start. Where do you wanna go? Do you want to create a new file? Do you want to open a folder, open a workspace? It gives you information about customizing and learning about code. So if I go to the little wheel down here, what this allow me to do is that allow me to change the color theme if I want Thio. So in this case, I like to use the light theme and I'll click and stall and it begins the process for installing. And then it will also tell you all the details about the current release off the power shell extension. So now that that's installed, you now see that there's a power shell commands explore icon here that if I click that that allows me to explore the different commands within Power shell. I go back to the settings, you'll notice something's been added here. I now have a power shall I s C theme. So it makes it look like the I S C so notice This is very much like the command explore that we had in the power shell i SC. So let's say I want to take a look at a script that I've already created. Going-to file Open file. I'm going to go down to the location where my scripts are located and we'll go ahead and open the view Dash stop service close the command explore and there we go. So we see our code is all here. Looks very similar to what we saw in the I S C. We see we have a terminal window here. I can close that terminal window. And if I want to run this script, I could simply go up to Terminal Run active file And it will run the script that I have in here. Type in CLI, no to client to you see, it goes through the process for running that I can even type in command into the window here into the terminal. So there we go. So you can see you can use the terminal console. It allows you to have multiple console windows in here so I could open up another session here and these air all separate console windows that you can work with. Let's say I wanted to create a brand new script. I'm going to create new file and then we're going to call this. I'm going to do a control asked to save this, and then we're gonna call this view sim info version three dot ps one. I'm gonna from the drop-down. I'm going to choose Power Shell from here so that it knows it's a power shell file so we can see that we've got the power shall icon. So it knows that the power shall file by type end dash computer name notice that it came up with the environmental variable. But I'm creating my own variable. And then, in this case, we're going to simply have that be the read host, like we did previously noticed that it's using a tell a sense here. It's giving me, showing me what the commands are so I could put those in. And if I hit Tab, it'll complete for me So many of the same features that we have in Power Shell. I put in double quotes here, notice it puts in the beginning and ending. It will do that for all of the symbols that are used for constraints within your code. So it makes it easy for you to not forget to put a closing symbol when you're typing and information. So we'll type in enter computer name Now that we have are variable I'm gonna put in my command. I'm going to do a get dash, Sim instance. So you see that until a sense is giving us the next things to put in. As I type a couple of letters, it allows me to tap complete, to put in the next parameter. If I go through my variables, I can put in my computer variable. So you notice that I'm saving a lot of typing by simply using the tab in the enter key to choose the options it's giving me. And then we'll put in the class name. Win 32 underscore operating system. Pipe that into select dash object. And then we're going to take the C s name. Notice that it's coming up with all of the options that I have the last booth time. So you'll see it. This is a tool that really allows you to be able to dive in and see what's going on, and it gives you a lot of insight into how to build better code. So we'll go ahead and save this run the act of and there we go. That's our command. So that's V s code. So this is a really cool tool. Hopefully, you check it out. We're gonna be using it through the rest of the module

Building a Parameterized Script

[Autogenerated] when building a script. I like to start with running the commands in the council as a single one line command or one liner. That way, I know that the commands will work and do what I want them to do. You can also do this in the I, C or V s code and then copy the commands into your script. The choice is yours. Whichever tool you finding works best for you. Use IT. Once I have my commands, I'll add them into my code editor. To begin building my script, I began adding variables and parameters for hard coded properties like computer named Parameter and username also things like credentials. So Aiken store the credentials for use. This will continue with my goal to make the script reusable. And if the script dictates the need for logic, I'll add it in so that it can run through multiple instances. This is real basic, and there's much more for you to learn about scripting that I'm not going to be covering here. However, this should give you a great foundation to move forward with scripting with power shell and last, make sure you keep it simple before we dive in. Let's talk a little bit about some script basics. The main components I'm going to focus on include using variables to store information and objects for later use. This allows you to move ah, heart coated command to something where we have variable so we can reuse information. This is really, really important, and it allows us to get much more efficient when we're doing commands. And also, as we're starting to move into script building, we'll take a look at using parameters. This allows you to make a script mawr like a commandment. When you call the script, it allows you toe enter parameters and values on the command line, just like you've seen us done with commands before. It's a good way to make your script reusable and start down the road of automation and tool building. Then I'm gonna introduce you to logic constructs that could be placed into a script to make decisions for you, such as if and for each. These allow you to doom or with your scripts. Last, I'll show you a technique for grabbing single object properties from a command. It's called member Linux Marais Shin. Basically, it works like select ash object in that it selects a specific property of your choosing from the objects output by a command.

Demo: Working with Script Basics

[Autogenerated] in our demo, I'll lay down some script basics that will help us as we move to building the information gathering script. Ah, cover setting variables, adding parameters to an existing script, look at some of the logic, constructs and finish with member enumeration. To start off this demo. I want to show you how this script runs, and then we're going to dive into the pieces behind the script as we start learning how to build our own tools. So I have this script. It's called Get Dash service status, and basically, what it does is it allows us to be able to put in a computer name. In this case, we're gonna put in D. C 01 as a parameter. And there you go. You see that? What it brings back is it brings back custom messages telling us about the status off all of the services on D. C. 01 So pretty simplistic script. But it's really coming down on the basis of really showing you that building scripts and tools is not that difficult. If we're just looking toe automates, um, little task, it really opens the door for you to be able to start learning and start building your own tools. So now let's take a look at her script in V s code. So here is my script that I have put together for this basic task and you'll notice on Lines one and three. I have lines that are basically remark lines and remark lines are going to start out with a hashtag or the number sign. And that denotes the power shell. That it's simply remark in your code, these air good for putting in notes for you and for the next person to use your script about what's going on. So to make this a parameter eyes script, the first thing what I need to do is I need to add in a parameter block song lines five through nine. I have my parameter block, and it starts with Paramus, and then you'll notice that it has a set of parentheses that are used after that. Inside the parentheses is where I put my parameters that I'm going to assign for the script. In this case, I want a parameter that brings in the computer name that's going to be put into one of my commands below, so I'm lying six. I define the parameter, and I define in his mandatory. So you notice inside the parentheses. I have mandatory equals the true. So what that tells power shell is that if I don't put in, ah value for this parameter when I run, the script Power show will prompt me to actually put that in online. Seven. You notice we define this as a string so that the value that's coming through is going to be a string value. Inside, right after string, you'll notice there's another set of square brackets, and what that denotes is that tells Power Shell. I can put in multiple values for this parameter, so I could put in multiple computer names for that and online eight. This is going to be the name of the parameter, and it's also going to match the variable within our code. In this case, it's going to be a computer name, so that's our parameter block. So once we have a parameter block in our script, then we go down to the actual code. So for my code, what I'm doing is I'm creating a variable cult services, and inside that I am storing the output of the command get dash service that's going to the computer name using the variable that we put in there. So that's going to store that all in the services variable so that I can then work with that. Then what happens is this moves into a four each construct. So for each what that does is it runs a set of commands that air inside the for each loop every time foreign object within an array that's brought in. So in this case, I'm taking the variable from lying 13 services and notice online. 16. Here I have service in services, so what that's going to do is for each object that's inside of services. I'm going to run everything that's inside of here from Lines 18 through 28. So will run all of these each time for each object that's inside of my array. So that's going to be run for each of the services that I'm pulling with the command. So online. 19. What I want to do is I want to get the service status. So what I'm doing is I'm calling the variable service and I'm dot notated in IT with status and this basically is member enumerating each of these. So what it's gonna do is it's gonna pull out specifically the status value from the object that's coming through. And then we're doing the same thing online. 20 for service display name. I'm calling the service variable. I'm dot notated that with the display name, and it will bring out just the display name value, property from the objects that are coming through. And then what I'm doing is I'm doing an if else statement here. So basically, this is a conditional statement. So what it's gonna dio is it's gonna look at the service status, variable the value of that. And if that's equal to running, what it's gonna do is it's gonna do a right output. And I'm just creating a custom message using the values that come through. So it's gonna write output service. Okay, Status of service display name is service status. Then it's going to go into if that condition is false, then it's going to go into the else statement. It's going to write that output into another statement basically saying check the service. The status of display name is service status and because we're using double-click votes here. It will bring through the values for each of those variables. So let's see how this works when we run it inside of power Shell notice if I put in a dash here, it allows me to put in the computer name. I'm gonna go ahead and run this without the computer name. So you see that it asked me to put in, Ah, computer name if I hit Enter. It'll ask me for a second because I had notated that this was a multiple value parameter, so I could put in another value here if I wanted. Otherwise, you can hit, enter and the command will go ahead and work. And so you see, what it's brought back for us is it's taking all of that information and then to put it into that custom message for us, we could also run this by actually running this using the parameter, and it does the exact same thing. And that's the process. You go through two parameter rise a script

Demo: Walking Through Parameterized Script Steps

[Autogenerated] So in our demo here, I'm gonna walk you through the parameter eyes script steps and show you in power shell how I would go and take a command from being hard coded to being a parameter rise script. So you have an example before we jump into the information gathering script. So in our step one, we see that we have a command were simply doing get dash service with the computer name of D. C. One and then I'm piping that into aware dash object where it's looking for a property of status that's equal to stop. So basically, this is gonna find all of the stops services that I have on D. C. 01 So if I go ahead and I run that command, we see that we've seen this before. It goes through, it brings back all of the stops services. So nothing brand new here, and that's, ah, hard coded command. Next up, what I'm gonna do is I'm gonna introduce variables into that. So we go to our next example notice I simply added online to a computer named Variable. In this case, we're using client 02 as the value that's being brought in there. The change. We have this online three instead of having that hard coded value. Now I've put in that variable. So it'll put in CLI No. Two for the value for that command when it runs. So we'll go ahead and run this when we go and run that we see exactly as we've seen before. It brings back all of the stops services. So that's how we start building that variable out. So the next step we're going to go into and step three is we want to parameter rise this. So we want to make this script run like it was a command lit or function like we've done many times before. So I create my parameter block here and inside there. I set this up so that the parameter is mandatory by setting mandatory equals the true online seven we've denoted this is a string and also want to make sure that this accepts multiple values. So we put those square brackets in there and you notice that we have the name for the parameter which matches the variable that we used before. And at this point, what we simply do is we simply copy this block of code over from here and we simply paste IT over and tar script here. I'm going to go ahead and save that. So we'll go over to the PowerShell Council and then the council. I'm gonna go ahead and run that same script that we just created. So we'll go does get Dash services. Example. Part three. It's gonna allow me to put in my parameter and value of CLI No. Two. I hit enter and there we go. So we see now we have a script that will do that for us and allow us to take input. So the Onley next step that we would have here if we needed toe add some logic into here is, let's say I wanted to do a four each. So let's say besides, just what IT wrana's far-as that command that I had, I wanted to do a couple of other task before each loop would allow me to run through that task on everyone off the objects that air coming through. So in this case, we would have for each of the target objects inside that variable, so basically each one of the services that air coming through it would perform what's on the code block here and again. All I'm doing is simply copying over my code that I've already written. So when I'm building a script, you're really just taking commands that you've already run. You verify that they know that they work and you're simply copying them into a framework. And so we have our perambulations. We have our four each. We've got our variables. Looks good. I'm going to go ahead and save that. Add will go back over to the power shell console, and I'm going to go ahead and run that example. So we go to example four notice it allows me to put in the computer name just like three dead putting CLI in two. And there we go. And that's how you take a hard code of command and move it to being a parameter eyes script. I hope you saw that that building scripts and tools isn't that difficult. It's just simply taking what you already do from the console hard coded command and simply adding some parameters. And it's saving it as a dot PS one Power shell script and running IT

Information to Gather in Script

[Autogenerated] for the information gathering script. The information we're gonna grab includes the operating system, information disk, free space, amount of system memory, the last reboot of the system I, p address and DNS. Name off the remote system and we wanna also have it right, the output to the screen in a format that gives us information. The reason we're creating this is simply so we have a quick tool that will go out and get common pieces of information that we often use when we're troubleshooting with end users. So now for the fun part, I'm gonna walk through building an information gathering script. So we're going to determine the script task and start building out the different commands that we're gonna use. I'm gonna add those commands into a script, and then I'm going to start creating variables and parameters to start making IT reusable. Then we're going to show you how we run it against a remote system and gather that information. So let's jump into building our first script when I begin building a script. The first thing that I start with is I really start with an outline of all of the tasks that I'm gonna dio. So basically, I list those all out inside of V s code and you noticed I use remarks for each of the lines. This gives me the basis for where I'm gonna build my script out of. I may have run many of these commands before. However, this gives me an idea of what exactly I'm gonna be doing throughout the script. And then once I have my outline, then I moved to the process of actually going through and running the commands and verifying that they all work as hard coded commands. So I'm gonna go to my next script here, and the first one we have is we're going to create a variable for the operating system. So we're using Get Dash Sim Instance, calling the wind 30 to underscore operating system for CLI. You know, too. And I'm pulling out the caption piece because that's gonna provide me the information that I'm looking for So we'll go ahead and run that when we access the variable, we see that that has Microsoft Windows 10 enterprise evaluation, which is the information that we want. Then the next item I'm going to go to is the free disk space. So for this I'm creating a variable called Dr I'm using Get dash W my object calling the Win 32 logical disk. And I'm using aware dash object to just get the C drive because that's the only drive that I'm looking for. Then what I do is I'm creating another variable called free space. And what I'm doing here is I'm bringing in that Dr Variable and I'm using member enumeration to call out the free space property. And then I'm dividing it by one gigabyte. And what that will do for me if we look at both of these pieces of information, is that will give me the information in gigs because that's what I want. In my report, PowerShell allows us to be able to divide by the unit of measurement Thio, get what we need out of there. The next piece we're gonna do is we're gonna work with memory and memories a little bit difficult, So I create a variable called memory in gigabytes. I do get dash, um, instance calling the win 32 physical memory against CLI a No to. And then I go through the process of pulling that information out. So I'm going to go over here to get memory toe, walk you through What exactly is happening here? So the first one when we run this this is going to bring back for us all the information about the physical memory. You see, I only have one piece of physical memory because this is a virtual machine. Real machines, you're gonna have multiple pieces of physical memory. So we need to take that into account UI when we're building on our information. So what I'm gonna do is I'm gonna take that same command I'm going to dot enumerated IT and pull out just the capacity from here. So when I do that, it shows me the capacity for those. If I had multiple pieces, it would show multiple items for the capacity for each of those. So now I want to bring that all together, and I'm gonna pipe that into measure or measure dash object, and I'm gonna some IT We'll go ahead and run that so it gives us the sum total off that, and then I'm going to again member enumerated. And you see, that would be the amount. Even though they're the same. That would be the sum total of all of the capacity on the remote system. And then I use my little math here to put that into gig. So it comes back with two gigs of physical memory. So that's the process that you walk through. You notice that you're using a lot of parentheses to separate out all of these, so it's, ah, bit complicated. But in the end, what this will do is this will get all of the physical memory on a remote system. It'll sum it all up, and it divided by Giggs to give you the total number of gigabytes of physical memory in a system. And if we go back to our commands, the next one is looking for the last reboot. So again, we're going and looking at Sim were using to get Cem instance and pulling up the last boot time. And when we run that, we see that I tells us the last booth time was Wednesday, March 13th at 5:16 p.m. And then the next pieces of information we're gonna get the I P address in the DNS name for the system creating a variable for DNS it's gonna go through the process for resolving the DNS name for that and looking for just the object type where it's an a record. Then what I'm gonna do is I'm gonna pull the name out of that piece of information and then I'm also gonna pull the I p out of that so we'll go ahead and load are variables. And then let's see what we get back when we actually run these. So you see that it would bring back the DNS information, and then it brings back the DNS name and then it brings back the I P address all pieces of information we want and the next piece of information we want is we want the DNA server off the target. So what DNA server is the target system using? Because one of the things that we know when troubleshooting is, it's often DNS is the problem. So we want to verify what DNA server our user and their computer is using to resolve things. So the first thing I'm doing is I am creating a SIM session that's gonna be used because get dash DNS client server address online. 29 doesn't accept dash computer name. So I'm using creating that sim session so that I can run that command remotely. So we'll go ahead and run the first command and then we'll put in our username m b admin put in my password. And now we'll go back up here and we'll go and run that command. And you see, it comes back with the I P address off the DNS server so we could verify that they're using the right Dana server.

Demo: Building a Remote Information Gathering Script in PowerShell

[Autogenerated] The next thing when I do, is I basically take all of those commands, and I'll put those into a script that we'll see in a second. But first I want to show you a base template that I use when I build out scripts at the top. What I have is I have a region that's going to be my help. So if you remember when we used help before, this is where you would put the information so that you can actually build help into your script. So you have your synopsis, which is gonna be a short description. You'll have the description, which is the long description, and then you couldn't put examples as well. Power Show will build out the cent tax for you, so that's all good to go. And then I like to put in. If we look at 12 through 16 in the script, name the Creator, the date when it was updated and if there's any references, so like, let's say I'm reusing somebody else's script. I always like to put that in as a reference, maybe to their block article or what have you just so when they get credit for it, too. If somebody else that's coming along, they can go and take a look at that next. What I'll do is I'll put in the variables and the parameters, and then I'll enter all of the task below. So let's see when we take all of this information, what it looks like when we put it all together. So when we go over to our script, we see that we have our help information. So I have a short synopsis of what this does. It gathers information from our health. This calls for using on those, then it gives us an idea of what the pieces of information are. And then I've created in here examples that you can pull up. So if you do help examples, it'll bring up all of these examples. So the next person to use this will know how to use this when they're working with IT. Then I've put in all my remarked information, and then I go through the process of adding in all of my other pieces of information. So we see we created our parameter block like we talked about previously, and I'm using the computer named Parameter that's going to be my variable. I'm creating a variable for credentials that's going to ask me to put those in That's going to be used in that new SIM session that I create. I'm also creating a variable for analysts because I want the output to show me who actually ran the script and then what I simply did as I dropped all of the commands directly from my command script into here. And I made a change for all of the variables where the client to name was in there, and I simply put the variable for computer name. That way it will use those variables as its run. And then the last piece of information. What I simply did is I I'm simply writing the output from this command to the host, so you'll see online 78. I'm simply creating a header Line 79 just breaking it up a little bit to give its, um, a little bit of formatting. And then on each line, I'm simply calling each of the different variables that I created throughout the script to provide me the information that I'm looking for. So computer name, last system reboot. You get the picture, so this provides us all of that information. So let's see how this works when we actually go through the process of running this. So in Windows Power Show, we're gonna go ahead and call that script. Get helped US. Support data dot ps one. Put in my computer name client, too. Company M B admin put in the password and there we go. All of the information has been output for us, so let's take a look at the help for this. If we do a help, get Dash helped us support it brings back all of our help information. So that's super cool and super helpful. So now let's try taking a look at the help with the examples. So we see there's all of the examples. So now we've built a script that we can use, and we can also pass it along to the other help desk people on our system. So let's try running this in power shell corps to see what happens. So we'll access the same script put in our computer name client, too, put in our credentials. If you remember, PowerShell core does this little bit differently. We actually put the credentials into the console as opposed to the pop out window. Oh, so we got most of our information, but notice it gave us an air here. The term W My object is not recognized as the name of a command lit. If we go back to our code, remember? What did we do here? UI used get dash W my object. Remember, I talked about W my object in Sim instance. Basically get the same information, which is correct. However, power Shell Corps does not support get dash w my object. So what we would simply need to do is we would simply change our script here To use Sim instance will go ahead and save that. Bye. Go back over here. Run my command again. What we'll see is now it runs so that shows you a couple things. One, it shows you make sure you're using Get dash Sim instance versus W my object, unless you're working with legacy and to it shows you the interchangeability and how those really pulled the same pieces of information. So that's how you would build a script