Learn Windows PowerShell 7 - In Just 2.5 Hours! (2021, With Scripting) | Genius Hub | Skillshare

Playback Speed


  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Learn Windows PowerShell 7 - In Just 2.5 Hours! (2021, With Scripting)

teacher avatar Genius Hub, Wouldn't You Rather Be A Genius ?

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

24 Lessons (2h 19m)
    • 1. Getting Started

      7:01
    • 2. Cmdlets

      7:48
    • 3. Parameters

      9:09
    • 4. Navigating the Console

      5:46
    • 5. Creating Items

      6:52
    • 6. Manipulating Items

      6:53
    • 7. Aliases

      4:32
    • 8. Variables

      6:04
    • 9. Profiles

      5:46
    • 10. Operators (Optional)

      3:55
    • 11. Objects

      6:08
    • 12. Pipeline

      4:32
    • 13. Pipeline Variable

      8:30
    • 14. Getting Started with Scripting

      6:29
    • 15. Conditional Statements

      5:21
    • 16. Functions

      5:20
    • 17. For Loops

      5:04
    • 18. While, Do & Until Loops

      5:18
    • 19. Arrays & ForEach Loops

      6:33
    • 20. Error Handling

      5:52
    • 21. Modules

      4:13
    • 22. Background Jobs

      4:30
    • 23. Remoting

      6:32
    • 24. Conclusion

      0:38
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

402

Students

--

Projects

About This Class

THIS COURSE IS KEPT UP TO DATE FREQUENTLY  -  LAST UPDATE: DECEMBER 2020

ADDED:  1 HOUR OF CONTENT!

Learning Windows PowerShell won't just take your IT skills to a new level, it will open a new portal!

No matter what your workflow is, learning PowerShell will add a new layer of efficiency and productivity.

PowerShell 7 is so versatile that if you do any task  in a computer you can always find a use for it.

Don't believe us?

Here is what some of our students have to say:

Jackues Martin:

"Outstanding. Great course and awesome instructor!"

Robert Milli (Translated):

"I was afraid that this course was for "absolute beginners", but the way in which the instructor explained allowed me to learn new things."

Gary Komarraju:
"Everything explained is very clear to understand for a beginner."


Become one of those happy students by enrolling now!

What you'll learn:

In this course you will learn exactly what Windows PowerShell is and gain valuable insight on how PowerShell actually works rather than memorizing commands.

Even if you are a complete beginner with no previous experience, you will learn everything from the ground up, step by step in a fun and engaging way.

PowerShell, and specifically PowerShell 7, is one of the most powerful tools in the windows operating system and it can be used to do almost anything.

From simple tasks such as moving, renaming and deleting files to troubleshooting your system or network and automating small tasks using PowerShell scripting.

By the end of this course, i am confident, that you will:

  • Have a deep understanding on what windows PowerShell is and how it works.

  • Be able to complete complex tasks in an instant using the PowerShell console and PowerShell scripts.

  • Effectively troubleshoot or manage a network from the PowerShell 7 console.

  • Use your computer much more efficiently.

  • Automate small tasks using PowerShell scripts.

  • And much MUCH more...

Specifically here is what you will learn:

PowerShell CmdLets, PowerShell Parameters, Creating & Manipulating Files/Folders & Hard/Symbolic Links, PowerShell Host Applications, PowerShell Variables, PowerShell Aliases, PowerShell Profiles, PowerShell Operators, PowerShell Objects, PowerShell Pipeline, Pipeline Variables, PowerShell Scripting: PowerShell Conditional Statements, PowerShell Functions, PowerShell For Loops, While, Do & Until Loops, PowerShell Arrays, PowerShell ForEach Loops, Error Handling in PowerShell Scripts, PowerShell Modules, Background Jobs, PowerShell Remoting.

All that & much more, in just 2.5 hours!

if you are ready to become a poweruser join me and the other students by enrolling now.

What are you waiting for?

Enroll NOW to get started!

Meet Your Teacher

Teacher Profile Image

Genius Hub

Wouldn't You Rather Be A Genius ?

Teacher

Class Ratings

Expectations Met?
  • Exceeded!
    0%
  • Yes
    0%
  • Somewhat
    0%
  • Not really
    0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Getting Started: Welcome to the first lecture of this course. In this lecture, we're going to learn how to get started with PowerShell. We'll start by learning what exactly PowerShell is. We will then learn how to launch PowerShell. And finally, we're going to check which version of PowerShell we have and if necessary, how to have greatest. Let's get started. What is PowerShell? Powershell is a task-based command line shell and scripting language developed by Microsoft and built on the.net framework. And while that might sound hired to comprehend, all you need to know is a PowerShell can be used for everything from system administration and task automation to managing operating systems and applications. Not only that, for PowerShell provides access to the following traditional command line tools, commandlets, the.net framework, Windows Management, Instrumentation, common information model, and more. We're going to learn what all of those are and how we can use them in the following lectures. Should I cannot only be used to manage Windows, but also other operating systems such as Linux or Mac. And important recent changes that PowerShell is now open source and it's based source code is available on GitHub, which is great news for everybody. Host applications. To instruct PowerShell to perform specific actions or complete tasks, we need some way of telling us exactly what it is we wanted to do. That's where host applications come in. These applications allow us to interact with the PowerShell framework in various ways. For example, a PowerShell contains a set of built in tools and actions called commandlets. By using a host application, we can leverage these tools and perform a myriad of tasks. You might have heard of the PowerShell console, or as it's also known, the PowerShell terminal. The PowerShell a console or terminal, is a preferred host when it comes to relatively small, simple, and non repetitive tasks. Powershell is also a scripting language, however, and the PowerShell console cannot be used to build and debug scripts. To do so, we need to use another host application, such as the Integrated Scripting Environment, which we'll learn more about in a following lecture. For now, however, let's stick with the console. How to launch PowerShell. Now that we know what the PowerShell console is, let's start using it to open the console, all we have to do is type the word PowerShell in our window search field from the options that appear, select the first result. It should be named Windows PowerShell. Powershell console will open at once. Well, that is all well and good. In many cases, you will be required to launch PowerShell as an administrator. To do so, search for PowerShell in your Windows search field, just like before, but instead of clicking directly on the first result, right-click it instead and select run as administrator from the window that appears. A console with administrative privileges or an elevated console, as it's also commonly known, can perform advanced tasks that an ordinary console cannot. However, be careful when running PowerShell with elevated privileges, the wrong operation can very easily break your computer. And that's why in this course would be primarily using PowerShell without administrator privileges. Now that our console is open, let's take a look around us. The first lines display basic information about our Windows version. Feel free to ignore these. And the next line, you will see the location or path I wish the PowerShell console is located now and it's called the current working directory. We're going to learn more about pads and locations in a following lecture. At this point, you might be eager to start using PowerShell. However, before we do so, we need to make sure the latest version of PowerShell is installed. How did check or upgrade your PowerShell installation? It is always a clever idea to use the latest version of PowerShell so that you can take advantage of the latest usability and security features to easily figure out which PowerShell version you currently have. Type a dollar sign into your PowerShell console directly followed by the word PS version table, Das PS version, and press Enter. While that may look complicated, you will soon find out that is a lot easier than it looks. Nonetheless, under Major, your PowerShell version should appear. Currently, the latest PowerShell version is seven. If you don't have the latest version, let's go over on how you can have it installed. First, open your web browser and head over to the official GitHub page, which I have conveniently placed at the lower right of your screen. Afterwards, we need to select which version of PowerShell we want to install. Generally, it is recommended that you void preview releases. So scroll down until you find the latest non-PV option and click on it. Next, you need to select and down on the installation file for your OS and architecture if you're using Windows, the appropriate version will be as follows. Once you find the appropriate version, simply click on it to begin your download. Once the download has finished, open your file and simply follow the instructions on the wizard to install it. Please note that PowerShell seven will co-exist. Current installation of PowerShell. After the installation is complete, if you already have a window of an older version of PowerShell open, use the PEW SSH command to switch the latest version. Awesome, you are now using PowerShell seven in Kayser console displays an error. Do not panic. For some older versions of PowerShell, this command will not work. All you have to do to launch the latest version is to search for PowerShell seven in your search field and select the first result. We've upgraded PowerShell window open. You are now ready for the next lectures. Summary. Powershell is an extremely powerful tool and hosts a myriad of useful features and tools. Launching PowerShell is quite easy. Simply search for PowerShell seven and select the first result. Just like we learned. If you're not using the latest version of PowerShell, make sure you check an upgrade your PowerShell insulation. That's it. You now know how to begin working with PowerShell and are prepared for the following lectures. Make sure you practice on your own what you have learned thus far. Until then, see you in the next lecture. 2. Cmdlets: Welcome to another lecture of the course. In this lecture, we're going to learn the very basics of PowerShell. We'll start by learning exactly what commandlets are. We will then learn how commandlets differ from regular Unix or Cmd commands. And finally, we're going to learn how the verb and noun of a command that affects its functionality. Let's get started. Wash our commandlets. Like we said in our previous lecture, PowerShell contains a set of built-in tools called commandlets. The name of those commandlets can be typed into a PowerShell host application and perform a designated task, such as everything from displaying specific information to changing windows settings. Will makes commandlets special is that since PowerShell is essentially a programming language, commands are objects of built-in classes and not just standalone executables. But what exactly does that mean? What are objects and classes? We previously mentioned the commandlets are objects. But what exactly are objects and classes? And objects in programming is an abstract datatype. It could include multiple properties and methods are even contain other objects within his methods or actions that can be taken and properties or information that can be viewed. Objects are also commonly referred to as class instances because of objects themselves are derived from classes. For the uninitiated classes are sort of like templates from which objects are created. If you are a programmer, you are probably familiar with both classes and objects, if not, until we learn more about them, simply think of classes as templates that can be used to create objects and objects as boxes that contain information as well as set of actions that can be taken. And now that we've got that cleared up, let's go back to commandlets. Commandlets versus commands. The best way to understand commandlets is by comparing them to something you might already be familiar with, such as regular commands and a Windows or unix environment. While both looks similar, PowerShell commandlets are fundamentally different from traditional commands. Main differences are as follows. Since PowerShell is fundamentally a programming language, commandlets are objects and not just standalone executables. Commandlets process objects and not text inputs. And the same way, objects are sent as output instead of plain text that can be traded from only a few lines of code and process only one object at a time. While you may not yet be familiar with some of the terminology I just use, do not worry. You will learn everything you need to know about commandlets through the progression of this course. Syntax. Now that we have a general idea, will commandlets are, let's start using them. Powershell command at always consists of a verb and a noun separated by hyphens, which makes them self-descriptive. Easy to understand. As an example, the guess item command at which consists of the GET verb along with the item noun, is used to retrieve information about an item. While the new item command that is used to create an item. The we're commanded functions depends on its Verb and Noun. Most common verbs are a new session, guess, stop, and start. To better understand this concept, let's take a look at an example. Let's use the guest child item commandlets to view every file and folder in our current directory. As you can see, every file and folder in the current directory is displayed. Verbs and nouns. While we've already mentioned a few commandlets aspire, let's have a look at a few more examples so that we can better understand them. Well, can not show you every commanded there is. We're going to take a look at the ones that are most commonly used. We will be categorizing our commandlets based on their verbs. Like we said before, a command, it behaves according to its verb and its noun. That is to say, commands that share the same verb perform an action in a way that is somehow similar. With that said, let's start with git commands. Commandlets that share the GET verb or used retrieve items. These items can be anything from the contents of a text file to which processes are being executed on a computer. For example, using the get processed commands, we can view every process in our computer. And as you can see, every process that is currently being executed in our computer is displayed. Set commandlets. Commands that use the verb says are used to modify or set some sort of value. This value could be anything from a setting or option windows to the contents of a text file. This example, I will use the set date commanded to change my computer's time. And our computer time has been successfully changed. New commands. Commands with a new verb created some sort of item. This could be anything from a new file or folder to a firewall rule as scheduled task, or even a local user. If you want to create a new computer users, for example, use a new local user commandlets. The console will then prompt you to enter a name as was password for the new user. If you do not want to create a new user after all, plus control and c to cancel the operation. Stop and start commandlets. Finally, we have commonness, the use the stop and start verbs. These commands can be used to stop or start a service process or some other function accordingly. For example, we can start an application using the startup process commanders along with the name of the application. A new notepad process should start at once. Note that the name of the application must be recognized by windows, meaning that only built in apps and services, as well as a few third party applications can be launched with this command lit. Similarly, using the stopped process commandlets, we can terminate the process we just started. Here is what that would look like. And our process has been terminated. You might have noticed that this time we included the hyphen name in our command as well. Hyphen name is what we call a parameter, and in this case is required for the stopped process commandlets to stop our process. But let's not get ahead of ourselves. Next lecture is all about parameters, and we will learn everything there is to know about them. Summary commands are basically special words that are made to perform a designated task. A PowerShell command, it always consists of a verb and a noun separated with a hyphen, which makes them self-descriptive and easy to understand. The way a commanded functions depends on its bourbon noun. Most common verbs are new, set, gets stopped, and stars. That's it. You now know a commandlets are and how they can be used. Make sure you practice on your own what you've learned thus far. Until then, see you in the next lecture. 3. Parameters: Welcome to another lecture of the course. In this lecture, we're going to learn how to use parameters. We will start by learning what parameters are. We will then learn what types of parameters exist and how they differ. And finally, how to get information on what a commanded does and how it can be used using get help. Let's get started. What our PowerShell parameters. Parameters in PowerShell, also known as arguments, are options Hub with the passage of information to Scripts, commandlets, and functions, or allow users to provide some sort of input. In the previous lecture, we use a parameter to instruct the stop process commanded to terminate a process. In a similar way, we can use various parameters with commandlets and make it perform a specific task or to alter their function in some way. Parameters follow commandlets, functions or scripts, and have the following syntax. As you can see, the name of the parameter is proceeded by a hyphen, which signals to PowerShell that the word following the hyphen is parameter. Afterwards, we have the value of the parameter which is separated with either a space or a colon punctuation mark. To better understand parameters, let's have a look at a simple example. Let's say that we want to view the details of a running process in our computer, such as the Chrome web browser. Before we do that, however, we need to launch Chrome so the get processed command that can retrieve its information. We can do that simply by using the startup process commandlets. And now let's use the get processed commandlets along with our parameter. Here is what that would look like. In this example. Get process is the commandlets. Name is a parameter and Chrome is the value of the parameter. Upon running the command, you can see that various details about every instance of Chrome are displayed. Note that the above syntax will only work for the values of parameters. They do not have space within them. For values that do contain spaces, we need to surround the value of r parameter in quotes. Here is an example. The quotes indicates to the console with the spaces separating the words do not constitute an additional parameter and or just a continuation of our value. Quotes are not only necessary for parameter values, but for any sort of text that contain the space within it. Parameter types. Depending on what their purpose is and how they are used, parameters are separated into multiple distinct types. Let's go over each one of them. Switch parameters. Let's start with switch parameters. Switched parameters do not require or even except values, and they can be used like a command line switch, such as this example. To include a username parameter is a switch parameter because it is now required value and it's used to instruct our command to display the username of the user. It is executing our process. Mandatory and optional parameters. Mandatory and optional parameters are pretty self-explanatory. Mandatory parameters are required for command to function of optional parameters or not. Take the following command. For example. The name parameter is mandatory. So the stopped process command knows which process to stop while the forcep router, which forcefully terminates our process, is not. In other words, while our command would function without the force parameter, I'll be at somewhat differently, or command would not function at all and would return an error without the name parameter that makes the name parameter mandatory and force optional. Named and positional parameters. Here's where stuff gets a little bit complicated. For some parameters, entering the name was not required and just specifying their value is enough. To better understand this concept. Take a look at the following command. As you may have noticed, we've included the value of the name parameter, in this case Chrome, but not the name of our parameter. That is because in this case the name parameter is positional. Whether perimeter is positional or not is defined by its commandlets. For example, if you were to type only the value and not the name of more than one positional parameter, your command that would aside which parameter you are referring to based on their order. On the get processed command at the first parameter in an order without a name and just a value always defines the name parameter. Usually only the most used parameters of Occam manage our positional. For now, don't worry too much about positional parameters. If you find them confusing, make matters simple and always include the names of your parameters. Every parameter that is not positional is named, which means that just specifying its value is not enough and typing its name is mandatory. Take this command, for example, which simply opens no pad in a minimize stays. The window style parameter is a named parameter. This command would throw an error or would be misinterpreted if we were to not specify the name of the window style parameter and typed directly its value. Here is what that would look like. Like we said before, because the window style parameter is named just typing it's value is not enough. And if we were to execute this command, it wouldn't throw an error. At this point, you might be wondering, how can you tell the type of parameter, the GetHub command that allows you to do that and much more. Getting information using get help. As the name implies, get help cannot only be used to display the parameters of the commandlets, but also a wealth of valuable information related to your commandlets, such as everything from what it is and what its function is to which of its parameters are required, whether they are named or positional and more do use it. Simply type GetHub followed by the name of a command lit. At this point, you might get an error about how files not being installed properly in your computer. If that is the case for you, simply execute the update, help commanded to install or update all of your files. This operation can take a while to complete. After the operation is complete, you might see an error in your console. That is because some of the URLs it use it to download your files might be invalid. If that is the case for you, simply ignore the error. The majority of your health files will be installed regardless. Upon running the GitHub command once more, you should see a small description of your command that as you can see, only basic information is displayed. Display all the information available, including information about the parameters on the command that we do use the full parameter as well. All the information available about the specific command will be immediately displayed to view details. But the parameters of a command is stroll up the GC, the list of parameters. Unreached parameter. You will see various information such as whether they are required or not, or if they're positional. Next to the word positional, you will either see the word named, which means that this parameter is a named or a number, in which case our parameter is positional. A parameter with the number 0 will always use the first unnamed value, y parameter with the Number One, we use a second unnamed value in that order, and so on. Pretty simple, right? Lastly, a particularly useful parameter is examples. Display usage examples for our command. Various usage examples will appear awesome, right? The get help command, it is an invaluable tool and we are making use of it throughout this course. So whenever you are unsure, simply use the GitHub commandlets to get the information you need. Summary. Parameters are words that can be typed after commanders to make it function in a specific way, depending on what their purpose is and how they can be used. Parameters are separated into multiple distinct types to get more information on what to command that does and how it can be used. Make use of the get help command, along with the examples, detailed or full parameters. That's it. You now know what parameters are and how they can be used. Make sure you practice on your own what you've learned thus far. Until then, see you in the next lecture. 4. Navigating the Console: Welcome to another lecture of the course. In this lecture, we're going to learn everything about pads and locations within the PowerShell console. We will start by learning what paths and locations are, will then learn how to navigate through the PowerShell console. And finally, we'll learn what both absolute and relative paths are exactly. Let's get started. Pads and locations. Just like we said in a previous lecture, the first few lines on the PowerShell console display basic information about our Windows version. And beneath that, the console displays the path or location at which the console is located. Now, this path is called the current working directory. The word directory in this context is interchangeable with folder. At this point, you might be wondering what is a path. In Windows, files and folders are organized using pads. A file path is an alternative name for the location of a file within the PowerShell console. The only way for us to navigate to the file system is by using file paths. Depending on where we position our console, we can perform an operation on the specific set of files and folders that are located within the directory. By default, the PowerShell console is located in a folder that's named after your computer's username. In my case, C colon users. Julian. C is the name of my drive users, the directory that stores every computer user, and Julian is the name of my computer user. This specific folder is what we call the root user directory because it contains all the files that are specific to this computer user. For example, upon navigating within from the Windows file manager, you can see that it contains the Desktop Downloads, Documents, and other folders navigating the file system. Now that we know what the pods are, let's learn how to navigate through the file system from our PowerShell console. Let's say that we want to navigate into the Desktop directory. We are currently located in the sea users Julian directory. In a previous lecture, we used the get child item commandlets to view the files in the directory. Let's do that once again. From the output we can see our desktop directory. To navigate there, let's use the set location commandlets followed by the name of the directory we want navigate into. As the name suggests, the set location command that changes our current working directory into the one we specify. And as you can see, our current working directory has been successfully changed to navigate one location backwards, or in other words, to navigate into our parent directory, we can use the set location commanded along with either the full location, which is C, uses julian, or alternatively, a nice short code is using two dots, one after the other, which will do the same. Relative and absolute paths. Depending on where we are located and where we want to navigate into, we can use either relative or absolute paths. Let's start with relative paths. Let's say that we want to navigate directly from our current location into my files directory, which is located within our desktop. To do so, we don't have to enter the full path, but rather only for the path that remains, which is desktop my files. In other words, we can subtract the part of the path that is equal to our current directory. In our case, we can simply type set location desktop my files instead of set location C users Julian desktop, my files, because we are located in the C, uses Julian directory. And as you can see, we are into the My Files folder. Notice how I surrounded the path and quotes. Like we said before, the quotes indicate to the console that the space is separated. The words do not constitute an additional parameter and are just a continuation of our path. Anyway, back to Potsdam. This type of path is called relative because it does not work from any directory. The directory we want to navigate into must be located somewhere within our current working directory. In our case, the Desktop folder was located within our current working directory. And from there, the My Files folder was located within it. On the other hand, if we wanted to navigate to a completely different directory, would have to enter an absolute or full path. Here is what that would look like. By using an absolute path, we can navigate to any directory regardless of where we are located. In this example, I successfully navigated into the My Documents folder, even though it was not located anywhere within the previous directory. Summary. In Windows, files and folders are organized using paths. A file path is an alternative name for the location of a file type. The Set location can manage along with the name of the directory you want to navigate into. And your current working directory will be changed into the specified directory. As the name suggests, relative paths only work relative to our current working directory, while absolute or full paths can be used from anywhere. That's as you now know how to navigate through the PowerShell console, make sure you practice on your own what you've learned thus fire until then. See you in the next lecture. 5. Creating Items: Welcome to another lecture of the course. In this lecture, we're going to learn how to create a number of items using our PowerShell console. We will start by learning how to create directories, will then learn how to create all sorts of files. And finally, we will learn what hired and symbolic links are and how we can create them. Let's get started. Creating folders. Throughout this course, we will require to create all sorts of items from our console. So it has files, folders, documents, scripts, and so on. We can do that using the new item commandlets. Let's start creating folders or directories. First, we need to navigate to the location in which we want to create our folder in, such as our desktop directory. Now that we are here, we can create a folder using the following command. The name parameter specifies a name for our item. The item type parameter specifies the type of item we want to create. In this case a folder. This is necessary because the new item commandlets can be used to create many types of items. Let's execute our command. And as you can see, a new directory has been created. The new item commandlets by default, always creates items in your current directory. If you want to create a your item in a different directory, you need to use the path parameter and specify that directory. You can specify both relative and absolute pads to minimize typing, you can also include the name of your item within the path itself without using the name parameter at all. So to create a folder within the manifold directory, we created previously, enter a backward slash at the end of your path, followed by the desired name for your new directory. And as you can see, our new folder has been created. Creating files. Apart from creating folders, we can create various types of files using the new item command. Before we do so, however, it is always a clever idea to check if a file with the same name already exists in your target directory. So you do not accidentally overwrite chooses. To do so, we need to use the test path parameter followed by our target directory along with the name of the file we wanted to create, including its extension. If the test path command that returns true, that means that a file the same name already exists. If not, it doesn't, and it is safe for us to creative. Doing so was quite similar to creating directories. Here is what that would look like. Don't forget to enter the extension of your file as well. In this case, I will create a text file using the item type parameter is unnecessary because the new item command that creates files by default. In case you do want to overwrite an existing file, include the force parameter as well. And as you can see, our file has been created. Parrot from creating text files, we can create all sorts of files assembly by specifying a different extension. For example, you can specify the DOC ex extension, create a Word document. Here is what that would look like. While navigating to the my folder directory, we can see that our file has indeed been created. In a similar way, you can create any sort of item, creating hired and symbolic links. Apart from creating files and folders, that new item command that can be used to create hired and symbolic links. But what exactly are these? Let's start with hired links. Hired links in windows are sort of like duplicates four or five, without actually using any disk space. Using hired links, you can make your files accessible from any directory regardless of where the original files are located. Since hired links contain all the data for the original file, you can safely relocate or even delete your original files without affecting the functionality of your hard links. Keep in mind that hired links can only be traded for files and not directories. On the other hand, symbolic links in windows are sort of like advanced shortcuts. They point to a file or directory that could be located anywhere in your computer. Unlike a hired link, symbolic links do not contain the data of the file they point to, but rather simply their path. If you were to move or delete the file, a directory of a symbolic link, your symbolic link would no longer work. Symbolic links can be traded for both files and directories. Now that we know what both hired and symbolic links are, less Create the du. So we're going to use a new item commandlets, just like before. So let's create a symbolic link into our desktop that points into our documents folder. Here is what that would look like. And as you can see, our symbolic link has been created upon opening and we can see the contents of our target directory. And a very similar way by replacing the value of the item type parameter from symbolic link into hired link, we can create hired links. For example, let's create a hyperlink into our desktop for one of the files we created previously. This time, I'm going to include the name of my link into the path parameter. And I'm also going to use relative paths. Specifying an extension for the name of a hyperlink is not required. And as you can see, our hired link has been traded successfully. Symbolic and hired links are very useful and can make managing your file system a lot easier. Summary. When creating files, we can include the names of the items we wanted to create at the end of our path. Make sure you test your target path using the test Pac-Man that for creating a file, especially if you're using the force parameter. So they don't accidentally overwrite any of your files. Hired links contain all the date of the original file without taking up any space. Symbolic links, on the other hand, do not use them both and make your file management easier. That's it. You now know how to create several types of items from your PowerShell console. Make sure you practice on your own what you've learned thus far. Until then, see you in the next lecture. 6. Manipulating Items: Welcome to another lecture of this course. In this lecture, we're going to learn how to execute and manipulate our files and folders in various ways. We will start by learning how to execute or perform the default action in an item, will then learn how to copy, rename, or delete our files and folders. And finally, how to take advantage of wildcards and manipulate many items at once. Let's get started. Executing items. We can launch executables, open files and documents, or otherwise performed the default action on every item directly. The PowerShell console using the invoke item commandlets. The invoke item commandlets simply performs a default action on a specified item. The default action depends on the item itself and is usually whatever happens when you double-click the item from the graphical interface. For instance, when using the invoke item command on a document, the default application that is associated with a specific file type will be used to open it. Such as a document with a Doc X extension, which will be opened using Microsoft Word. Let's try using the invoke item commanded on a text file. For example. Since the file we want to execute is located in our desktop, you must first navigate there using the set location commandlets. And now all we have to do is type the invoke item command followed by the name of our file. Since the default application for opening text files in my computer is an Notepad. Notepad open and displays its contents as if we had double-click on the file itself. Apart from logic, applications are viewing files. We can open and view the contents of a specific path. To do so, you can simply type the path after invoke item command lit. The Windows Explorer successfully launches and displays the contents of the specified path as if we had navigated their copying, renaming, and deleting. Using PowerShell, we can manipulate and perform a number of operations on our files and folders in various ways. Let's start with copying. The copy item command that can be used to copy or duplicate items from one location to another. To use it, simply type the copy item command followed by the path parameter to specify your item and the destination parameter to specify your target. A new file should be immediately created. In a similar way, we can copy or duplicate entire directories. So once again, let's use a copy item commanded along with the path and destination parameters. This time I'm also going to use the recurse parameter, which tells are commanded to copy all the items, including any subfolders and any items that might be located within our directory. And as you can see, our folder was copied successfully. The other recurse parameter only the folder itself would be copied and not any of its contents. In a similar way, we can use the rename item commanded to rename our items. The past parameter specifies the file or folder that is to be renamed. And the new name parameter, the name we want our file or folder to be renamed to. And as you can see, our file has been successfully renamed. Finally is you would like your move or delete an item. You can use their move item command. Once again, I'm going to use the recourse parameter to delete any files or folders within our directory. And the force parameter, which removes any hidden or read-only files as well. And her file has indeed been deleted. Pretty simple, right? Wildcards. We could also use wildcards, perform an operation to multiple items at once. Wildcards are special symbols that take the place of characters or words. The most commonly used wild carrot is the asterix. For example, we can use a wild character MOOC, both the my folder and the my files folders from our desktop. Since both folders begins with the word my, delete them both, you can type the word mind followed by a wildcard. So once again, use the remove item can manage by the word mite and a wildcard all within quotes. When using wildcards, it's always a clever idea to surround them in quotes, since some of your items might contain spaces within their names, as is the case here. And as you can see, every file that begins with the word has been deleted. Alternatively, we can perform an operation only to a certain file type by adding a wildcard before and extension. This command, for example, would leave every file.txt extension. Once again, I'm using the recurse parameter to remove any text files with any of our directories. And the force parameter to remove hidden or read-only files as well. And our text files have been deleted. We can even perform an operation to the files and folders of an entire directory simply by using a wildcard itself. Here is what that would look like. If I were to execute this command, it will delete all the files on my desktop. And that is a perfect example of why I should be careful when using wildcards. The wrong command can perform an undesired operation to your files. What makes wildcards extraordinarily useful? They can be used pretty much any commandlets. And it can make doing repetitive tasks easy, such as executing or manipulating multiple files and folders. The invoke, copy, rename and remove item commands to accordingly. We will be making use of wildcards throughout this course. Summary. Use the invoke item can manage, reform the default action on a specified item. The default action is usually whatever happens when you double-click the item from the graphical interface, uses a copy rename and remove item command is to duplicate, rename and delete files and folders accordingly. While carries a special symbols that take the place of characters or words. And they can be used to perform an operation to multiple items at once. That's it. You now know how to execute or manipulate your files and folders. Make sure you practice on your own what you've learned thus far. Until then, see you in the next lecture. 7. Aliases: Welcome to another lecture of the course. In this lecture, we're going to learn how to use aliases to make our lives easier. We will start by learning what aliases are. We will then learn how to use aliases to improve our productivity. And finally, how to create an remove our very own aliases. Let's get started. What are aliases? Powershell commandlets, names follow a verb noun convention, which sometimes can be cumbersome to type, to minimize typing and make it easier for users who are familiar with other shells. Just command prompt. Powershell supports aliases. In simple terms, an alias has an alternative name for commandlets, function executes, boot, script, and so on. Powershell includes a set of built in aliases to view them. Type get alias in your PowerShell console. All the aliases that are available in the current PowerShell session will be displayed at once. If you are familiar with any shells such as command line or unix, you will notice that PowerShell includes many aliases that can make your transition to PowerShell much easier. Such as the DIR command from the Windows Command Line, which is an alias for the get child item commanders or cash from the unix operating systems, which is an alias for the get content commands. While the equivalent commands may not function exactly the same way, there are close enough that you can do work without knowing the correspondent commandlets. Aliases can also be abbreviations of commandlets. For example, the CPA alias is an abbreviation for the copy item commandlets. These types on aliases can save you keeps of time by reducing the amount of typing you have to do. Scroll through the output of the get alias command and discover a few aliases on your own. Creating and removing aliases. While there are plenty built-in aliases, you might want to create a few aliases on your own. To do so, you will need to use the new aliased commandlets. For example, let's say that we want to create an alias previewing our network adapters. The command line for that is get net adapter. So to create our alias uses a new alias commandlets, followed by the name parameter, the name of the Ailey's within quotas, along with the value parameter and the name of the command list. Here is what that would look like. An alias with the name and a for the getName adapter command that has been created successfully. Let's try using it. As you can see, the aliases working as if we had type the command itself, the parameters of the command that can be used as well without any complications. For example, we can use the physical parameter with our alias to display only physical adapters the same way we would on the command with itself. Keep in mind that by default, aliases that we create will only work in our current session. However, our aliases can be made permanent by using a PowerShell profile. We're going to learn more about profiles in the following lectures. To remove an alias He created by mistake or that you no longer need user move item commandment. The remove item command is not made for deleting aliases exclusively, but rather, as the name suggests, it removes items in general. That way we have to specify the type of item we want to remove, in this case an alias. So to remove our alias type the remove item commandlets followed by the word alias, directly followed by a colon, and the name of the alias within quotes. Upon typing our alias once more, we can see that is has indeed been removed. Aliases are extremely useful. I can save you a lot of time and effort. Use the get alias command to get familiar with the built-in aliases and practiced by creating and removing a few aliases on your own. In summary, in simple terms, an alias is an alternative name for commanded function executable script, and so on. Use the get alias command to view every available alias. Corresponding commandlets. Create your very own alias using new alias or move them using the remove item commandlets. That's it. You now know what aliases are and how to use them. Make sure you practice on your own what you have learned thus far. Until then. See you in the next lecture. 8. Variables: Welcome to another lecture of the course. And this lecture, we are going to learn everything about variables and PowerShell. We will start by learning what variables are. We will then learn what are the several types of variables. And finally, how to create edges and remove our very own variables. Let's get started. Was our variables. A variable is a unit of memory which is used for storing values. You can store all types of values in PowerShell variables, such as the result of a command, names, values, pods, et cetera. In PowerShell, variables are represented by text strings that begin with a dollar sign. Here are a few examples. The names of the variables are not case sensitive and can include special characters or spaces. However, variable names that include special characters or spaces can be difficult to use and thus should be avoided. Powershell has several types of variables. Let's go over each one of them, starting with user-created variables. As the name suggests, these are variables that are created by users. By default, the variables that are created by you exist. Only one of the PowerShell window was opened. When the PowerShell window closes, these variables will be deleted. To make your variables permanent, you would have to use a PowerShell profile, which we are going to learn how to do later on. Automatic variables. These variables are created and maintained by PowerShell itself. Users can change the values of these types of variables. As an example, the ps home automatic variables stores the path of your PowerShell installation directory. We will make use of this variable later on. Preference variables. These variables store any user preferences for PowerShell. They are created by PowerShell and are populated with default values. Users can change their values. For example, the maximum history count variable determines the maximum number of entries in the Session History. The Session History is a database of your most recent commands and can be accessed using the up and down arrow keys. We will learn more about these variable types when we learn how to personalize PowerShell. Creating variables. To create a new variable symbol using assignment statements to assign a value to the variable. An assignment statement is, as the name suggests, a statement which assigns values to variables using an assignment operator, simply type the name we were variable followed by an equal sign and your desired value. In this example, I created a variable named path and assign the location of our system 32 directory as devalue. Note that locations that contains spaces within them to be surrounded in quotes. Just like the value of a parameter, you can view a list of all the variables in your PowerShell session by using the get variable commandlets. To display the value of a variable. Simply type the name of the variable and press enter. Its value will immediately be shown. You might recall that we use the ps version table dot PS version variable at the very beginning of the course to check our PowerShell version. The ps version table dot p has version variable contains information about our PowerShell version and in a very similar way, by typing its name into our console, we were able to view its value. We can also use the value of our newly created variable as input for a command list. For example, since our variable contains a path, we can view the contents of that directory by using the get child item commandlets. The contents of the system 32 directory, who'd be immediately shown. To change the value of a variable, simply assign a new value to it by using an assignment statement once more. To make a variable Mt. 9. Profiles: Welcome to another lecture of the course. In this lecture, we're going to learn everything about PowerShell profiles. We will start by learning what Profiles are. We will then learn where are the several profile locations. And finally, how to create an execute our very own custom profile. Let's get started. What our PowerShell profiles. Many of the items that you create in PowerShell and most commands, the execute effect, only that session. When you close your console, any items, aliases, variables you might have set, will be deleted. To save these items and make them available in every future session, we can add them to a PowerShell profile. A PowerShell profile is simply a fancy name for a script that runs whenever PowerShell starts, you can add everything from aliases, functions, variables, modules, and more to your profile. So they are available every time you launch your PowerShell host. Profile locations. Powershell looks for a profile in several locations. We can determine under which circumstances of profile that's executed depending on where we created asked. These circumstances include user is using the computer or which PowerShell host application is being used. The word user refers to the users on your computer and hosts, or the applications which you use to interact with PowerShell. So far, we have been using only one host, the PowerShell window or console. And other host is the Integrated Scripting Environment or ISE, which we will learn about more in the following lectures. For example, we can choose to execute a profile only for the current computer user and the correct host application, which in our case is the PowerShell console. The various profile locations are listed below by the precedence order. The first profile has the highest precedence based on our list. If, for example, if we wanted to have our profile executed for all users but only the current host. In this case, the PowerShell window. We would have to create our profile and location just corresponding with the all users current host description. And the paths mentioned above. Ps home variable is the installation directory for PowerShell, and the home variable is the current user's home directory. Creating profiles. Now that we know what Profiles are and how they work, let's create 1. First, we need to place our profile in one of the profile locations. For easy access, PowerShell includes some automatic variables, which contains the location of every profile. Let's say, for example, that we want to create a profile only for the current user and the current host. In that case, we would have to place a profile in the location dictated by the profile dot current user, current host variable. If you would like to, you can view that path simply by typing the name of the variable into the PowerShell host. Notice how this variable does not contain the location of the directory in which our profile is located, but rather the location of our profile itself. To create our profile, we need to use the new item commandlets followed by the item type parameter, the Word file, along with the path parameter and the location we want to create our profile in. You might be wondering why we didn't type a name for our profile. And that's because both the name and the extension of our profile are already contained within our path. Once again, since we installed our profile in location dictated by the profile dot current_user, current host variable. The profile only be executed for the current user and host. Right now our profile is empty. Let's use a notepad to customize it. Simply type notepad followed by our variable. With the Notepad open, you can add the commands that you would like executed every time you open PowerShell. For example, you could create any of your aliases or variables. After customizing the profile to your needs, saved the file, and then restart your PowerShell. Your aliases and variables will be available at once. If your PowerShell profile script was not executed, aliases or variables are not available. It might be because of some of the default restriction than PowerShell. If that's the case for you, launch PowerShell as an administrator and run the line given below to set the PowerShell execution policy to remote sign, which will allow your profile script to get executed. In the case you want to launch PowerShell without executing any of your profiles open PowerShell with the no profile parameter from the run dialog box. Profiles are wonderful time savers at an extremely useful tool, practice by adding a few commands to your profile on your own. In summary, a PowerShell profile is simply a fancy name for a script that runs whenever PowerShell starts. Powershell looks for a profile in several locations. We can determine under which circumstances a profile is executed, depending on where we created at. Take advantage of the built-in automatic variables that contain the locations of PowerShell profiles to rapidly create yours. That's it. You now know what Profiles are and how you can use them. Make sure you practice on your own what you have learned thus far. Until then. See you in the next lecture. 10. Operators (Optional): Welcome to another lecture of the course. And this lecture, we are going to learn everything you need to know about operators on their types. We will start by learning what operators are. We will then learn what are the several operator types. And finally, how to use operators to complete several tasks. Let's get started. What are operators? Operators in PowerShell or a combination of symbols, letters, and numbers that perform a special operation or interact with the command list or variable in a special way. Powershell has a substantial number of operators. You most certainly won't be able to remember them all. However, you can refer to this lecture anytime you are in need of one. Operators are separated into several types, such as assignment operators, comparison operators, redirection operators, and more. While we cannot discuss all of them in this lecture, we're going to take a look at the ones that you are most likely to use. Assignment operators. We have actually already used this type of operator before to create variables. As the name suggests, assignment operators are used to change a sign or append values to variables. In this example, I use the plus equals operator to append the number two to my variable. Arithmetic and unitary operators. Arithmetic operators are used to calculate values in a command or expression. You could add, multiply, subtract, or divide values, and calculate the remainder of the division. Similarly to arithmetic operators, unitary operators, increment or decrement variables or object properties. For example, to increment the variable age from nine to ten, you type a plus plus. Comparison operators. Comparison operators are used for comparing values or test conditions. Redirection operators. These operators can be used for creating files from the output of a command or expression. Pipeline operator. Probably the most used operator in PowerShell. This operator can be used to transfer or pipe the output of one command into input or another. It will go in depth about this operator in an upcoming lecture. Splits and joined operators. These operators divide and combined sub-strings. The split operator split a string into substrings, while the join operator combines multiple strings into a single string. Logical operators. Logical operators are used connect conditional statements into a single complex condition. Type operators. You can locate and change the.net type of an object by using type operators. In summary, operators in PowerShell, or combination of symbols, letters, and numbers that perform a special operation or interact with the command list or a variable in a specific way. There are several types of operators, such as assignment, arithmetic, urinary, comparison, redirection, and so on. Use operators to create manipulation or compare variables to create text files from output, split and join strings. And it changed the type of an object. That's it. You now know what operators are and how you can use them. Make sure you practice on your own what you have learned thus far. Until then. See you in the next lecture. 11. Objects: Welcome to another lecture of the course. In this lecture, we're going to learn everything you need to know about PowerShell objects. We will start by learning what objects are exactly. We will then learn how to use the pipeline to explore objects. And finally, how to view an object's properties and execute its methods. Let's get started. What our objects. In our previous lectures, we briefly mentioned the commandments are objects and that they get input and send output in the form of objects as well. Let's take a deeper dive into PowerShell objects. If you are a programmer, you might be familiar with the concept objects. An object is basically a representation of anything. In our case, objects are basically a collection of properties and methods to better understand this concept, let's make that smartphone that's right next to you into a.net object, its properties or its screen, battery, motherboard, and so on. And it's methods are turned on make called open browser, et cetera, in an analog way, every command that is made out of properties and methods, the properties or the names of the items that make up our object and methods are pieces of code that can be executed to take an action. To better understand how commandlets process objects, let's take a look at an example. What exactly happened here? The get processed command list without any parameters is used to achieve information about every process in your computer and place them in many individual objects. So every name you see here is a separate object that was created for the specific process. At the top, we can see the names of their properties. I'm below their values. For example, ID is a property name that is shared among all the objects that were retrieved. The numbers beneath it are the values that every one of those objects contains for that specific property. Pipeline. To make matters simpler, let's instruct the get processed command to return only one object. For example, let's open our notepad and use the name parameter to instruct the get processed command that to return only the object that contains the methods and properties related to the notepad process. The PowerShell console does not display any of the methods we can execute on the object, but instead shows us some of the properties it thinks are most useful to us. In this case, the ID, name, CPU usage, and more. We can use the pipe operator along with a get number command to view every method and property that is contained within that object. Let's break this command down. Like we said before, get processed. Commandlets will gather information and create an object that contains properties and methods related with the notepad process. The pipe operator will transfer that object into the guest member commandlets, which will then pick apart the object and neatly display us the names of its properties and methods, as well as some information about them. Upon running the command, the assortment of members and properties that make up our object will immediately show up. We can see other items as well, but for now, feel free to ignore these. At the very top we can see what type of object this is. There are several types of objects and we will learn more about them in an upcoming lecture. Properties. From the list of properties you might recognize the names from the ones that were displayed earlier, such as the ID or the CPU property. As you can see, this object has a lot more properties than the ones that were displayed to us. We can view the values of all these properties. Let's do the value of the main window titled Poverty, for example. First, we must save our object into a variable. Our newly created variables should now contain our object. Let's type the name of our variable to view our object. As you can see, some of the properties of our object appeared just like they did when we use the get processed notepad command to view the main window titled property, simply type the name of the variable directly followed by a dot and the name of the property you want to view. And as you can see, the window title of our notepad successfully appears. In the similar way, you can view the value of every other property this object contains. Methods. Let's go back to the output of the get Member command. Apart from properties are object contains methods. Like we said before, methods are pieces of code that can be executed to complete an action. For example, we can execute the kill method to instruct windows to kill the notepad process. Since we've already saved our object into a variable, all we have to do is to type the name of the variable directly followed by a dot, the name of our method and two parentheses. And as you can see, I'm method was executed and the notepad process was killed. This method of executing or viewing the properties of a variable is called dot notation. Once again, you can use this method to execute any of the available methods objects of the very essence of PowerShell. And it's particularly important that you fully understand them. So rewatch this lecture a few times if you need to and make sure you practice on your own. In summary, an object is basically a representation of anything. And our case objects are basically a collection of properties and methods. You can use the pipe operator along with GET member commandlets to view every method and property that is contained within an object. Use dot notation to view the values of an object's properties or to execute one of its available methods. That's it. You now know what objects are and how they work. Make sure you practice on your own what you have learned this fire. Until then. See you in the next lecture. 12. Pipeline: Welcome to another lecture of the course. In this lecture, we're going to learn everything you need to know about the PowerShell pipeline. We will start by learning what the pipeline is. We will then learn exactly how the pipeline works. And finally, we're going to take a look at a few simple use cases for the pipeline. Let's get started. What is the pipeline? We briefly explained and use the pipeline in the previous lecture. What exactly is the PowerShell pipeline and how does it work? A pipeline is a series of commands interlinked with the use of a single vertical line, which is called the pipe operator. With the use of the pipe operator, the output of each command is used as an input from the next. A pipe can be used more than ones, connecting multiple commands and creating a complex chain. These chains of commands can only be processed from left to right. Many other shows support command piping. However, piping is particularly powerful in PowerShell since objects are sent and received and not just text. Let's take a look at a simple example of a pipeline. Let's first open our NOPAT. And then Let's use the get processed command along with the pipe operator followed by the stop process commandlets. Your notepad process should be immediately terminated. But what exactly happened here? The good process commandlets created an object representing our notepad process, passed it on via the pipe operator into the stop process commandlets, which use the information contained within that object to stop the notepad process. Not all command that support piping, we can find whether a commanded accepts piped objects by using the GitHub command along with the full perimeter. As you can see in this case, the stop process commandlets does support piping. All the other commands that can be piped, not all of them can be connected with one another. That's because some of them except different types of objects from each other. For example, we cannot use the output of the getSomeService commandlets as input for stop process because one uses a surface type object while the other can only operate unprocessed type objects. We can use the get Member command to find what type of object a commandlets outputs. In this case, our output object is of the System.out service dot system controller type pipeline examples. Now that we know more about the pipeline, let's take a look at a few simple ways we can use it. Starting with format list. The format list commanders can be used to format the output of a command in the form of a list in which every property is displayed on a separate line. You can use the property parameter to specify the properties that appear in the output and the order in which they appear. If you would prefer, you can use the format table commanded instead, which will form at the output in the form of a table, you can again use the property parameter to select the properties that you want to display. An alternative for the property parameter of the format list and the format table commandlets is select object. We can use Select Object to display only select Properties from the output of a command list. Finally, by using the soar object commanded to sort the output. And by combining the previous commandlets, we can select unsolved our output all with just one command. And this example, I chose to have the output sorted based on the CPU usage. The pipeline is extremely powerful and we will be making use of it throughout this course. In summary, a pipeline is a series of commands interlink with the use of a single vertical line, which is called the pipe operator. Not all commandlets support piping. You can find out whether a command that accepts piped objects by using the GetHub command along with the full parameter. Some commands operate on diverse types of objects and thus cannot be connected together via the pipe operator. That's it. You now know what the pipeline is and how it works. Make sure you practice on your own what you have learned thus far. Until then. See you in the next lecture. 13. Pipeline Variable: Welcome to another lecture of the course. In this lecture, we're going to learn everything you need to know about the pipeline variable. We will start by learning what the pipeline variable is exactly. We will then learn exactly how this variable works. And finally, we're going to get familiar with a few use cases for this special variable. Let's get started. The pipeline variable. Within a pipeline, there was a certain automatic variable which is managed by PowerShell, and it can be used along with some other commands to complete various tasks. Automatic variable is called PS item, and it simply contains the value of the current object in the pipeline. Remember how we would save an object into a variable so that we could look at its properties or execute its methods. This will PowerShell does with this variable. It simply saves every object that passes the pipeline into this variable. Using this variable along with some other commands, we can perform special tasks. Let's take a look at these commandlets starting with for each object. For each object. Before each object command that executes a piece of code for every object that passes through a pipeline. To better understand this concept, let's take a look at a simple example. Let's start off by loading the numbers 123 into our pipeline. Let's then pass these objects using the pipeline and into the foreach object commandlets. Then within curly braces, let's use the right host command to print the value of our PS item variable. And let's execute our command. What's exactly happening here? Let's break it down. Using commas. We can load several objects into our pipeline. In this case, the numbers 123, then pass these objects using the pipeline into the for each object commanded. Like we said before, this combated executes a piece of code or a command for every object that passes through our pipeline. Within Carney braces, we have the command that is executed for each one of our objects. Finally, here's what the PS item variable comes in. Like we said before, the PS item variable contains the value of the current object in our pipeline. And so through every iteration it's value changes and becomes equal to one over objects. The right host commanded then reads the value of our PS item variable, recognizes that it contains a number type object and prints the number into our console. This process is then repeated for every one of our objects using the for-each object commandlets, like we said before, simple enough, right? To minimize typing, we can take advantage of a few abbreviations. As you can see from the output of the gate Ailey's commanded. Let's now type our previous command with our abbreviations. So instead of typing before each object commanders type a percentage sign. And similarly, instead of typing the PS item variable, enter an underscore in his place. As you can see, our command functions in exactly the same way. Apart from printing numbers, we can replace right hosts with any command us to accomplish any task. For example, we can print the value of a property for every object that passes through our pipeline, such as the name property for every file in our current directory. To do so, let's first type the get child item, can model it and use it as a source of our objects. Let's then pass or objects through our pipeline and into the foreach, I'll just commandlets just like before. Finally, within curly braces, let's type the PS item variable followed by a dot and the name of the property we want to print and execute our command. As you can see, the name property of each one of our object and successfully printed. Well, that's all well and good. Let's take a look at a more complex example, such as creating multiple files. Let's start by loading the names of the files we want to create into our pipeline. That's then pass them into the for each item command, which is abbreviated using a percentage sign. Then let's use the new item commanded along with the PS item variable, which is abbreviated using an underscore, educate each one of our files and turn. And now that our command is ready, let's execute it. And as you can see, our fuzz had been created. But how exactly does this work? Let's break it down. The quotes TO PowerShell that we are specifying strings. Powershell then creates objects and each one of our strings and pass them into 4H item command it using our pipeline for each object then executes a new item commanded for every one of our objects, at which point the new item command, it reads a string from the PS item variable, which contains a string type object and uses it as the same name for the New File it creates. Simple enough, right? Let's take a look at a slightly different version of this command which can help in minimizing typing. So instead of typing the entire names of our files, let's type only the part of that differs between them. Let's send pass them through our pipeline into for each object, which will then execute the new item commandlets as the value for the new item commandlets. Let's enter the word file followed by the PS item variable and the extension we want our new files to have. And let's execute our command. Success. Do not worry about the air appearing on the screen. It simply tells us that the files you want to create already exist. You might be wondering about why the extension of our file was interpreted as the names of the property. That is, we code is being used in the context of a value for a commanded. In other words, the new item can manage, understands that the dark text after our PS item variable is a part of the name of our file and not some property or method of the contained object. Where object, apart from executing a command for every object in a pipeline. Another example of using the PS item variable is filtering output. To do so, we need to use the word object commands, which allows us to do just that. For example, let's say that we want to make our get processed command is only display objects that have their name property equal to Notepad. To do so, let's first open our notepad so that the get processed command, it can retrieve the appropriate object. Now let's type the get processed command and pass its output into the where object commandment, which would then check the name property of every object in our pipeline using the EQ operator. And let's run our command. Like I said before, where object checks every object that get processed command creates through the use of the PS item variable and the EQ operator. If an object matches our conditions, some of its properties will be displayed into our console. As you can see here, you might have noticed that this output is identical to what we used to get in previous lectures. When we instructed that get processed command to return only the notepad process directly. That is because PowerShell itself uses a somewhat similar internal process. From here, we can even pass the object that we floated through the where objects mindless using another pipe and perform some operation on it. For example, you can use a stop process commandlets to determinate the selective process. Here what that would look like. This time, let's abbreviate beware object commandlets using a question mark. At the very end, let's add our stopped process commandlets and executed. Any process and my star condition will now be stopped at once. Myosin looking upon back come out as a beginner, looks intimidating, doesn't know who you've come so far. Summary, PS, items and automatic variable that contains the value of the current object and a pipeline. The for each object command, it executes a piece of code for every object that passes through a pipeline, the wearer object command that allows us to select or filter objects from a pipeline base on specific conditions. That's it. You now know what a pipeline variable is and how it can be used. And make sure you practice on your own what you have learned thus far. Until then, see you in the next lecture. 14. Getting Started with Scripting: Welcome to another lecture of the course. And this lecture we are going to learn how it gets started with PowerShell scripting. We will start by learning what PowerShell scripting is. We will then learn how to install and configure our Scripting Environment. And finally, we're going to get familiar with our Scripting Environment and create our very first script. Let's get started. Powershell scripting. The problem with using the regular PowerShell console is that you always have to type commands, but that's where scripts come in. You could automate many tasks and make your computer life easier by using PowerShell scripts. A script is a file containing multiple lines of commands that are executed one after the other by the PowerShell console. Meaning that you'd only have to create a script ones instead of constantly typing commands to complete a repetitive task. Powershell scripts, he's a PS1 extension and it can be used to automate repetitive tasks, such as the deployment of applications to many computers at once, or various housekeeping activities that are organizing or deleting unwanted files. Setting up our environment. To help with the creation execution on debugging a PowerShell scripts, we need to use a code editor. Granted it that is not strictly necessary, scripts can be created simply from a file with the PS1 extension and a text editor such as Notepad. However, a dedicated code editor provides syntax coloring, multiple line editing, IntelliSense, tab completion, selective execution, and many other useful features. So that's what we'll be using. Up until PowerShell version five of built an application named Integrated Scripting Environment could be used. Since then, however, it has been depreciated and a different host must be used instead. Microsoft recommends Visual Studio code, so that is what we'll be using. Let's go over on how it can be installed. Obviously, if you already have Visual Studio Code installed on your computer, skip this step. Otherwise, head over to this web site, code dot Visual Studio.com and download the appropriate package for your operating system. After the download is finished, installing Visual Studio by going through the wizard. Now that we have Visual Studio up and running, we needed to download and install the official PowerShell extension. Simply click the last icon from the panel on the left and then type PowerShell in the search bar that appears. Select the first result and click the Install button. After the installation is complete, PowerShell will prompt you to select a color theme. I always go with dark. And that's it, are scripting environment is now installed and configured. First steps. Powershell by default does not allow user created scripts to be executed. Before we start creating scripts, you must first change the setting. To do so, first, open PowerShell seven as an administrator. And then type set execution policy, followed by the remote signed value. The set execution policy command that is responsible for controlling which scripts can be executed. The remote signed value tells are commanded to only allow the execution of a script if it was created by us or trust the developer. If necessary, type y to confirm the operation. In other scripts can be executed. Let's go back to Visual Studio and create our first script. First script. Let's create our first script. To create a script, go over to File and select new file. Your new script should be traded at once. Let's save our script by going over to file and selecting Save As. From here, select the directory in which you want to save your script. I'll go for the desktop, then enter name for your script. And finally, as the type, scroll down until you find PowerShell and click it. And that's it. Our new script has been created, but it is looking rather empty. Before entering code into our script, we must first get familiar with the interface. At the top half you will see the scripting panel. Here. We can insert the code that'll make up our script. The other half contains a PowerShell console, which will allow us to view the output of our executed scripts or to execute any commands. From the left panel. Click the PowerShell icon to reveal the command explorer. The command Explorer can be used as governed new commands and insert them into your script or view information about them. For example, by clicking the question mark button. Next we'll commandlets. You can view various information and use it examples from the website that opens. Similarly by clicking the button with the Pen icon, you can insert commands into our script. Awesome, right? Now that we are somewhat familiar with the interface, let's add some code into our script. Let's start by using the right host command to print something into our console. Simply type the right host command into scripting panel, followed by the text you would like printed into your console within quotes, just like you would from the PowerShell console itself. To execute the script, click the play button in the left panel and click the run and debug button. In our console, we can see that our script was executed successfully. And alternative way of executing scripts without using Visual Studio is by first navigating to the location or from a PowerShell console. And then typing a DOS, a backward slash and the name of your script. The script will be executed at once. Its output will be displayed in your console. As you can see here. Summary. A script is a file containing multiple lines with commands that are executed one after the other by the PowerShell console. To help with the creation, execution and debugging a PowerShell scripts, we need to use a code editor such as visual studio code. Make sure to change your execution policy setting to allow user created scripts to be executed. That's it. You now know how to set up your scripting environment and to create scripts. Make sure you practice on your own what you've learned thus far. Until then, see you in the next lecture. 15. Conditional Statements: Welcome to another lecture of the course. And this lecture, we are going to learn everything you need to know about conditional statements. We will start by learning how to create simple if statements. Ask for user input. We will then learn how to implement else and else if conditional statement. And finally, we're going to learn how to check the value of an object's property and perform an action accordingly. Let's get started. Simple conditional statements. Let's implement some logic into our script. In PowerShell, we can use if statements to run code blocks only when a specified condition evaluates to true. One of the most common uses for if statements is checking variables. So let's create a variable and prompt the user to enter a value using the read host commandlets. Followed by our question in quotes. Then let's use an if statement to check if the value of our variable is greater than five using the GET operator. Within our if statement, lets add, the code will only be executed if our statement evaluates to true. For this example, I will use the right host command to print some text into the console. Now that we're ready, let's execute R script. Let's start by entering a value that will make our statement return false. In other words, let's enter a number lower than five. As you can see, when the value of our variable is lower than five, the console does not display any output and our write host command that is not executed. However, when we enter a value higher than five, our if statement evaluates to true and the right host command is executed priciple right? Else and else if statements. The similar way we can also specify one or more additional conditions in case all of our previous conditions evaluate to false by using else if statements, all we have to do is type else-if followed by air condition within parentheses. The EQ operator stands for equals. And as the name suggests, it checks whether our two values are equal. Within curly braces, we can enter the code is to be executed in case our condition evaluates to true, just like we did before. Finally, there's also add an else statement. Get executed only when all the other previous conditions evaluate to false. Here is what that would look like. And let's execute our command. Let's make our first condition evaluates to true by entering a number greater than five. Now let's do the same with our else if statement by entering the number five. And finally, let's enter a number lower than five. As you can see what our number is greater than five, the coded in the first condition is executed and the value is five. The second condition is executed. And at every other case the third condition is executed, which means that our value is lower than five. Checking properties. Apart from using conditional statements to check variables, we can do pretty much anything. For example, we can create a script that checks whether an application is responding or not by checking the responding property of its process type object. First, you must prompt the user to enter the name of a process using the read host commandlets. Then we must create a second variable to store the output of the get processed commanded, which will retrieve an object for the name of our process, which is specified by the variable we created previously. Finally, let's create conditional statements that check the responding property of our object and perform an action accordingly. For this example, if the process is responding, I will simply use the right host command and print a message to the console. Otherwise, if it is not, I will once again print an appropriate message to the console, and it will also execute the kill method, determinate the unresponsive process. And our script is ready before we run it. However, let's first open our notepad Using the star products command. So the get post can retrieve the appropriate object as the name of a process. Let's enter notepad to see if it's responding or not. And in this case, it obviously is whoever had our nope, had been crashed out. The code within our else statement would have been executed instead. In the same way, we can check any other properties and values by using conditional statements. Summary. In PowerShell, we can use if statements to run code blocks only when a specified condition evaluates to true. Use else if statements to execute code in case all of your previous conditions return false and use L stamens to execute code for every other case. Take advantage of conditional statements to check the value of a property within an object and execute a method accordingly. That's it. You now know what conditional statements are and how to implement them. Make sure you practice on your own what you have learned thus far. Until then. See you in the next lecture. 16. Functions: Welcome to another lecture of the course. In this lecture, we're going to learn everything you need to know about PowerShell functions. We will start by learning when functions are, will then learn how to create an execute a function to complete a task. And finally, we're going to learn how to implement and use one or many parameters with our function. Let's get started. Was our functions. A function is a guru of commands that together perform a task. With functions, we can organize our code and make it easier to understand. A function can be as complex as a PowerShell commandlets or a program. We all that said, let's create our first function. Let's simply type the word function followed by the name you would like it to have. You can assign any name you want to your function, but it is recommended that you follow a verb. Now naming convention similar to PowerShell commandlets, so that the purpose of your function can be easily understood. Just after that, open and close two brackets within them, place any code you would like executed. For. In this example, I will use the get date commanded to display the current date and time. To tell a PowerShell to execute our function, we can simply type its name just like we would on a commandlets. Note, we need to execute our function after we define it. In other words, typing the display datetime command above our function would lead to an error because PowerShell would not know which function we are referring to. So we must always define our function first for asking PowerShell to execute it just like we did here. Let's run our script. The command within our function will be run as if we had typed them in our console. Awesome, right? If you want to add multiple commands to your function, simply enter each one in a new line. For example, we can use the right host command to print that our function has been executed. Here is what that would look like. And let's execute our function once again. As you can see, both are commands have been executed. Function parameters. Just like commandlets, you can create parameters for your functions as well. You can define any number of parameters and you can even specify a default value for your parameters. For simplicity's sake, let's create only one parameter for now. Within the brackets of your function, simply type power m and within parentheses, create a variable as your parameter. To add a default value, simply assign a value to your variable. This value will only be used if you don't specify one when you call your function. If you don't want to add a default value, simply type the name of the variable by itself. In this example, I will create a small function that displays the name and ID of a specified process. All we have to do is type the get processed command followed by our parameter and pipe that into the format list parameter. We will need to display the name and ID of the specified process. Before we execute our script, Let's open to applications so that the get processed command that can receive their IDs, in this case Chrome and NOPAT. To do so, let's use the startup process can mileage. And this do the same for the notepad. Now, let's run our script. As you can see, the ID of the process is displayed successfully. Let's run our script once again, but this time let's not specify our parameter so that the default value is used instead. And as you can see, our default value was used instead. We can also add multiple parameters to our function simply by typing them one after the other, separated using commas. This example, I will simply trade a parameter along the right host commandlets that prints as specified texts into the console. Here is what that would look like. Now that we're ready, let's execute R script. And as you can see, our second parameter is working at our text is printed into our console. Pretty simple, isn't it? Summary. A function is a group of commands that together perform a task with PowerShell functions, we could organize our code and make it easier to understand. A function can be as complex as a PowerShell commandlets or program to create a parameter simply power m within the brackets of your function. And within parentheses, create a variable as your parameter. Assign a value to your variable to use in case one is unspecified, to add multiple parameters, simply type them one after the other, and separate them using commas. That's it. You now know what functions are and how to use them. Make sure you practice on your own what you have learned thus far. Until then. See you in the next lecture. 17. For Loops: Welcome to another lecture of the course. In this lecture, we are going to learn everything you need to know about for loops. We will start by learning what PowerShell loops are. We will then understand how a for loop works and learn how to create us. And finally, we're going to learn how to use for loops to complete tasks. Let's get started. Powershell loops. One of the most basic but simultaneously powerful programming concepts are loops. We can use loops to repeat and instruction until a specified condition is met. There are many types of loops you can use in PowerShell for loops, while, do or do until loops. And finally, for each loops. In this lecture we're going to go over the first type for loops. For loops. The for loop is used when you need to execute your commands a certain number of times or as an integral to create a for loop, use the following syntax. The Ina's placeholder is used for the creation and initialization of a variable with a starting value. The condition placeholder resolves to true or false. Powershell evaluates the condition every time the for loop runs. If this condition resolves to true, the commands, the command block gets executed and the condition is evaluated again. Otherwise the loop stops. Therapies placeholder executes each time the loop repeats. Typically, it is used to modify the variable that is evaluated inside the condition part of the statement and control the interval. The commands block represents a set of commands that are run each time the loop is executed. To better understand for-loops, let's take a look at an example. Let's start off by creating a variable named i and initializing it with a starting value of one. For our condition, let's use the l e operator, which stands for less or equal back so that the condition evaluates to true when the value are variable is less than or equal to 20, otherwise it evaluates to false. Now let's increment our variable by one for every execution of the loop. Finally, let's use the right host command to print the value of R i variable. And let's run our script. As you can see, our code was executed repeatedly only while the value of our variable was less than 20. And our condition evaluated to true. The moment our condition of iOS defaults and R i variable reach 20, execution stops. While printing numbers is cool. Let's take a look at a practical example. Let's say that we want to create five new text files in our desktop. Here is the script we're going to use. Since I want to repeat my instruction five times, I'll make the condition if I were to true only when the value of the i variable is less than five, just like we did before. Within our loop, let's first create a variable that will hold the name of our file. Since our files can all have the same name, I added the i variable within our value. So the names of our files be filed one, file two, and so on. Then we need to create a second variable that will hold locations for our new files. We're gonna include the names of our fuzz within a specified path. In this case, our desktop directory by using the join path command lit. This command will include the names of our files within one path by combining them both. Alternatively, if you want to make matters simpler, you can specify the name and path separately to the new item commanded directly using the appropriate parameters. Ben, let's use a new item can manage, create each one of our files in turn. Finally, let's use the right host command to print to the console that a file has been created. Now that we're ready, let's run our script. And as you can see, the joint path command combined our path and name of our file successfully and five new files had been traded. For loops can be a little hard to understand at first, especially if you are not a programmer. So re-watch this lecture if you need to add practice on your own. In summary, loops are some of the most basic but simultaneously powerful programming concepts. We can use them to repeat and instruction until a specified condition is met. The for loop is used when you need to execute your commands a certain number of times or as an interval. To create a for loop, first, you need to create and initialize a variable, specify a condition, and finally, specify the interval of your variable. That's it. You now know what for-loops are and how they can be used. Make sure you practice on your own what you have learned thus far. Until then, see you in the next lecture. 18. While, Do & Until Loops: Welcome to another lecture of the course. In this lecture, we are going to learn everything you need to know about while loops. We will start by learning what while loops are and how to create them. We will then learn how to run our loop at least once regardless of our condition by using do. And finally, we are going to learn how to reverse to condition of a while loop by using until. Let's get started. While loops. While loops are great for when you're task does not require to be executed a certain number of times, but rather when it's dependent on a certain condition. As the name suggests, while loops repeat an instruction only Wireless specified condition is met. If that condition evaluates to false, the execution will stop immediately. Let's create the simplest possible while loop. Simply type while followed by your condition within parentheses. As our condition, we are going to use the automatic variable true, which as the name suggests, always returns true opponents evaluation. And let's use the right host command to print something into our console. Let's run our script. This operation will print the word height in your console rapidly and indefinitely. It might also crash your computer. Thing about while loops is that they have no speed limit. A loop such as this one will run your code so rapidly that it might hang your CPU and crash your PC. That's why for this type of loop, it's important that you always have a commander's, such as start sleep, which will prevent your operation from getting executed too frequently. Are commands will now be every second indefinitely. Let's create another while loop. But let's use a real condition this time. So let's create a variable and use a number one as its value. For that condition, let's make it evaluate to false only if our variable is not equal to 0 using the any operator which stands for not equal. And let's use the read host commanded to ask for a new value for our variable every time the loop is repeated. In this case, we don't need to stop our loop from executing too quickly because it will always wait for us to give it an input. And now that we're done, let us run our script. As you can see, our loop will keep executing for as long as we enter a value other than 0. As soon as we do, our loop will stop. While do. Just like the wild loop, a do while loop will repeat and instruction only Wireless specified condition is met. The key difference is that with a do while loop, our code will always be executed at least once. Matter if our condition evaluates to true. For the execution to be repeated, however, are conditions must be met. This happens because a while do loop evaluates our condition only after our code has been executed. Let's modify our previous while-loop and convert it into a while do loop. To do so, first, let's change the initial value of a variable to 0 and then simply replaced the word wild width due at the very bottom type while and specify your condition. Now that our script is ready executed. Had this been a wild loop, it would not have been executed at all because our condition would have returned false. However, this being a while do loop, our script works exactly the same way as it did before because our code was executed before our condition was evaluated. In other words, while do loops execute our code at least once. Do until. Finally, we have the two until loop. Unlike a while do loop a due until loop executes our code only while our condition evaluates to false. Let's replace the word while with until an R script and see what happens. Let's also change the text that is to be printed and execute your script. As you can see, our loop is only executed while the value of our variable is 0. The execution stops for any other number that A's because an until loop only executes our code while our condition evaluates to false. If our condition evaluates to true, the execution immediately stops. It's basically the complete opposite of a while loop. In summary, while loops are great for when you're task does not require it to be executed a certain number of times, but rather when it's dependent on a certain condition. The key difference between a while and while do loop is that with a while do loop code is executed at least once, no matter if the condition is met. Unlike in a while do loop a due until loop executes our code only while our condition evaluates to false. That's it. You know what while, while do and until loops are and how to use them. Make sure you practice on your own what you have learned thus far. Until then. See you in the next lecture. 19. Arrays & ForEach Loops: Welcome to another lecture of the course. In this lecture, we're going to learn everything you need to know about arrays and for-each loops. We will start by learning what arrays are and how we can create them. We will then learn how to manipulate values within our arrays. And finally, we are going to learn how to use a for each loop to iterate through every item in our array. Let's get started. Arrays. And array is a data structure that is used to store a collection of items. These items can be of the same or a different type. Arrays are stored into variables and are created in a similar way. To create our first array, let's create a variable and simply assign multiple values separated by commas. Are array is now created. Alternatively, you can use the range operator to add up every value in a certain numeric range. This example creates an array containing the values from one through ten. The third method is by using the array operator, which is useful for when you don't know how many objects will be included in the array. This example, an array will be created that contains an object for every process in your computer. Now that our array is created, Let's view its contents to display every element in an array. Simply type the name of the array in your console and press enter. You can also display a specific item from the array by using an index starting at 0. So 0 be the first item in the array, one, the second, and so on. For example, to display the second element in the array, you can type the following. You can also use the range operator within the index to display a range of objects. We can see how many total elements exist in an array by viewing the value of the count property, manipulating values. Now let's see how we can manipulate an array to change the value of a particular element in the array, you can simply use its index and an assignment statement. In this example, the value of the second item in our array will be changed 20. Apart from changing the value of an element, we can use the plus equals operator to add an element. Our item will be added to the last position and will be the last item in the array. Using the.count property, we can see that indeed our element was added on the count of elements has increased by one. To combine two arrays into a single new array, we can use the plus operator. Here is an example. First, let's create two arrays. And now let's create a new array that combines our two previous arrays. And let's see its contents. Lastly, if you want to delete any array, simply assign an empty value onto it. And an empty value is represented by the null automatic variable. Your array will be deleted at once. For each. Using a for each loop, we can run one or more commands for every item in an array. Here is an example of the simplest possible for each loop. First, let's create an array containing the values a, b, c, and d. Then let's type for each followed by two parentheses within them, create a new variable without a value followed by the word in and the variable we created previously. The i variable will take the value of every one of the items in our array variable through every iteration. And finally, with an our loop, Let's use the right host commandlets to print the value of R i variable. Now that we're ready, let's execute our script. As you can see, the first time our loops execute, the value of our variable is set to a and the right host command, it prints its value. For the next iteration, i is set to be and so on. After the final item in the array is iterated through PowerShell, exit the loop. Pretty simple, right? Let's take a look at a more practical example of a foreach loop. As an example, let's create a loop that checks the extension of every file in our directory and deletes any text files. Here is what that would look like just like before. Let's create a variable that will hold our array. In this case, our files variable will be filled by an array of objects from the ghetto child item commandlets. Then let's create our foreach loop using a new variable named file. This variable will contain the value of every item in the array we created previously. Within our foreach loop, let's use an if statement that checks whether the extension property of every one of the objects in the arrays equal 2.txt. And then let's use the remove item command, delete them in turn. For the purpose of this demonstration, I will use the what if parameter, which makes sure that our files are not actually deleted, but rather PowerShell, We'll just pretend to do so. If you'd like to actually delete your text files, simply remove this parameter. Now, let's run our script. Success. As you can see, the text files were found, I'm PowerShell pretended to delete them. Arrays are particularly useful and we will be making use of them throughout this course. In summary, An array is a data structure that is used to store a collection of items. These items can be of the same or a different type. To display a specific item on an array using an index. An array index always begins at 0. So 0 is the first item on the array, one is the second, and so on. Use for each loops to iterate through and interact with every item in the collection or an array. That's it. You now know what arrays and for each loops are and how to use them. Make sure you practice on your own what you have learned thus far. Until then. See you in the next lecture. 20. Error Handling: Welcome to another lecture of the course. And this lecture, we are going to learn everything you need to know about error handling. We will start by learning what the try and catch blocks are on how to use them. We will then learn how to converse non-terminating exceptions into terminating ones. And finally, we're going to learn how to use the finally block for any code that should be run regardless if an exception occurs. Let's get started. Try and catch. Error handling in PowerShell helps ensure that errors in a script do not cause issues and unexpected results. Have a look on how error handling can be useful. Take this small script, for example, to simulate an error or is more commonly known an exception, let's use the throw command. This would be the equivalent of a command that will potentially cause an exception to occur. Just below that, let's use the white host command us to print the word hello into our console. Upon running our script, as you can see, the throw command successfully throws an exception and our right hosts commandlets does not get executed. Let's handle this error and perform an action accordingly using the try and catch blocks. Here's what that would look like. First, type the word try and open and close two brackets within them. Enter your potentially problematic code. In this case r throw command. In a similar way, we can create our catch block, which will execute the code within his only ones code within the try block throws an error. Now let's run our script. Let's break down what just happened. The throw command caused an exception to occur. Since our command is within a try block, the catch block was executed. Finally, are right host commandlets was executed successfully on the ward hello was printed into our console. Let's take a look at another example. Let's start by requesting a name for our new file and saving it into a variable. Similarly, Let's also request a path within our tribal. Ok, let's enter the new item command, which will create our file. And in case our catch block is executed, let's use the right host command to print into our console that an error has occurred. Finally, let's print the word w1 into our console. Now that we are ready, let's execute R script. Let's enter a random name for our new file. And let's make the new item commanded to throw an exception by entering a path that does not exist. As you can see, the new item commandlets did indeed throw an error, but the code within our cache block was not executed. However, the script continued, executed the right host commandlets and printed the word w1 into our console regardless. So why did this happen? There are two types of exceptions in PowerShell. Terminating a non-terminating, terminating exceptions make the running script exit. But non-terminating exceptions do not. A catch block is only executed if a terminating exception occurs. In this case, the new item command through a non-terminating exception. And that's why our catch block was not executed. To make sure that our cache block is executed, we can convert the non-terminating exception into a terminating exception simply by entering the error action parameter or EA for short, to our commandment alone would stop as a value. Let's try our script once again. Just like before, let's enter a random name and an invalid path. As you can see, the catch block and successfully executed this time. A simpler way of converting every non-terminating exception that might occur into a terminating one is by setting the value of the error action preference automatic variable to stop. Way we won't have to spend time locating which command is throwing non-terminating errors. Here is what that would look like. Once again, let's enter a random name and an invalid path are terminating exception was once against successfully converted into a terminating one. Finally, lastly, we can use a finally block to specify actions that should be run regardless if an error occurred. This is mostly used for cleanup activities such as closing database connections, removing files, closing file locks on, so on. That's out a simple finally block into our script. So just like before, type the word finally and within curly braces and the code that is to be executed and execute your script. Let's enter a random name and a valid path this time so that we can actually create a file. As you can see, the code within our block finally was executed even though an exception did not occur. In summary, we can handle errors and perform an action accordingly using the try and catch blocks. Every exception terminating by setting the value of the error actions preference automatic variable to stop or by using the error action parameter. Use finally blocks for any code that should be run regardless if an error occurred, such as closing database connections, that moving files, closing file locks on, so on. That's it. You now know what error handling is and how it can be used. Make sure you practice on your own what you have learned thus far. Until then, see you in the next lecture. 21. Modules: Welcome to another lecture of the course. In this lecture, we're going to learn everything you need to know about modules. We will start by learning what modules are and how you can use the gallery to find them. We will then learn how to install them, whether they are from the gallery or in the form of a folder. And finally, we're going to learn how to view, get more information and uninstall any of the modules in your computer. Let's get started. What are modules? A module is a package that contains PowerShell commandlets, functions, variables, aliases, providers, and more. Developers who write PowerShell commandlets use modules to organize their commandlets and share them with others. Users then installed and import these modules into PowerShell and use our newly available commandlets, just like they would use any other built in commandlets. Finding modules. Powershell, it comes with several pre-installed modules, which are also usually called core modules on a Windows computer, when you install or enabled new windows features, PowerShell modules that are part of those features also get installed automatically. However, you can install a third party modules by going over to PowerShell gallery.com slash packages. This is the official repository for user main modules and it contains hundreds of them. Along with modules, the repository contains scripts and other useful resources. Browser search through the website and find any modules that are necessary or helpful for your use case. Installing modules. If you find a module that you want to install from the gallery, simply click on the package and copy paste provide a command onto your PowerShell console. You're modulus should be installed and ready to go within minutes. Modules that are not from the gallery usually contain a Windows installer. They can complete the installation for you. If you happen to receive a module in the form of a folder with files within us. Here's what you need to do to install it. First, you need to create a modulus folder in the following path. The hope automatic variable contains your user's directory and my case, see users Julian. Then you need to copy your entire folder into the newly created modules directory. From here, your module will be important to automatically, by PowerShell knows that modules are imported automatically only when they are stored in the location specified by the ENV colon PS module path variable. Modules in different locations can only be imparted by using the import module commandlets. Here is what that would look like. Managing modules. You can view all the installed modules in your system by using the get Module Command has along with the all parameter. If you happen to find a module that you want more information on, you can use the GET command, commandlets along with a module parameter and the name of your module to get a list of every commandments contained within that module. Finally, you can uninstall a module from your computer by using the uninstalled module commandlets, and along with the name of your module and summary. A module is a package that contains PowerShell, commandlets, functions, variables, aliases, providers, and more. You can install third-party modules by going over to PowerShell gallery.com, four slash packages. This is the official repository for user made modules, and it contains hundreds of them. If you find a module that you want to install from the gallery, simply click on the package and copy paste provide a command onto your PowerShell console. You're modulus should be installed and ready to go within minutes. That's it. You now know what modules are and how they can be used. Make sure you practice on your own what you have learned thus far. Until then, see you in the next lecture. 22. Background Jobs: Welcome to another lecture of the course. In this lecture, we're going to learn everything you need to know about background jobs. We will start by learning what background jobs are and how they can be used. We will then learn how to create background jobs for commandlets as well as scripts. And finally, we are going to learn how to view the output of a job on how to stop or deleted. Let's get started. What our background jobs. You might have noticed that when you run a PowerShell script or commandlets, you can't get back to the prompt and until it stops running. But what if you want to start another script or use the PowerShell prompt to perform other activities in the meantime. In such cases, background jobs can come in very handy. With background jobs, you can execute a script or a command in the background while still having full control over the console. Starting a job. Here's a script we're going to use as an example. It simply prints the word working every 1 second by leveraging the true automatic variable and the starts need commandlets, just like we learned in the previous lectures. To run a command as a background job, you need to use the start job commandlets along with the script block parameter and your command within curly braces. The script blood parameter is used to specify the command that needs to be executed. If you want to run a script, you need to use the file path parameter instead, followed by the name or path of your script. Upon running the command, the background job will immediately start. When a background job starts, PowerShell returns to the prompt immediately, even if the job has yet to complete. In that way, you can easily continue working without any interruption. Managing jobs. To list all the jobs that have been started in the current PowerShell session, you can use the get job commandlets that get job commandment with display among others, whether our job has been completed or not, and the command that is being executed while that's graze, What if we want to see the output of our job? To do so, we need to use the receive job Camilla's followed by the name of our job. The full output of our script or command would be displayed immediately. Please note that receive Job displays the entire output only if the job has been completed. Otherwise, it displays only the output that has been generated. And thus, you would have to retype the received job commanded to review any new output. Another crucial point is that if you retype the received job commandlets, only any new output will be displayed. Any output that's already been displayed will not be shown. However, you can use the key parameter to always save the entire output and not have it automatically deleted every time it's displayed. Alternatively, you can use the weight parameter, which will not return you to the prompt until the job is complete. The entire output will also be available. Similarly, you can use the weight job commanded to suppress the PowerShell prompt until the job is complete. Lastly, you can use a stop job and remove job commandlets to stop and remove jobs accordingly. Here's what that would look like. And let's try removing our job. Success. A nice little trick that will make managing your job easier is saving it into a variable. That's way you won't have to remember what name PowerShell assigned to your job. From here. Using this variable, you can easily manage your job. Awesome, right? Summary. With background jobs, you can execute a script or a command in the background and get full control over the console while your task is being executed. To run a command as a background script, you need to use a start job commandlets along with the script block parameter and your command. To execute a script, you need to use the file path parameter. Instead. Use the received job commandlets to view the output of a job and use the stop job and are moved. Jock commanded to stop and delete jobs accordingly. That's it. You now know a background jobs are and how they can be used. Make sure you practice on your own. What you have learned thus far. Until then, see you in the next lecture. 23. Remoting: Welcome to another lecture of the course. And this lecture we're going to learn everything you need to know about PowerShell promoting. We'll start by learning what are motoring is and how it can be used. We will then learn how to configure imposing on the host and guest machines. And finally, we're going to learn how to establish persistent and interactive sessions with a remote computer. Let's get started. What is remote using? Powershell or emoting is a useful feature that lets you run any PowerShell commandlets on one or many remote computers. It can be used from everything from and establishing persistent connections, starting interactive sessions, or even running scripts on remote computers. Whoever the remote computer must be first configured properly for remote management. Configuration. To enable PowerShell promoting, you must first go over to the remote computer, or as we will be calling it from now on the guest computer and type the following commands into a PowerShell console with administrator privileges. The force parameter tells our commandlets has not prompt us for confirmation at every step. If your computer's network profile is set to public, PowerShell will output an error if that's the case for you. To enable PowerShell over emoting, you would either have to set your network profile to private or uses skip network profile check parameter to enable promoting regardless. If you're host, which is the computer you are going to initiate the connection from Andrew Guest are part of a domain. That's all the setup you would have to do. Otherwise you'd have to configure the trust host setting on both the guest and the host so that your systems would know they can trust each other. Before we do that, whoever we need to know the computer names of both our host and guest, let's simply use the system info command to find them out and scroll up until you find the name of your computer. Alternatively, a local IP address can be used instead. Now, let's add the name of our host into our trusted host setting using the following command along with the name of our host. Like we said at the beginning of this course, commandlets with a cent verb, I used to set some sort of value, in this case, our trusted host settings. And let's do the same. And our host computer. We're once again going to use a set item command. This time wherever we need to enter the name of the guest computer instead of the host. Both the host and our guest computers are now configured to trust each other. If you are in a safe environment, you could also use a wildcard to trust every computer is obviously does have security implications, however, so be mindful. Finally, you have to restart the emoting servers using the following command, which will do just that. Promoting is now fully configured and ready to be used. Starting sessions. There are several distinct ways of using PowerShell repurposing to start an interactive session with your guests. Use the Enter PF session commanded along with a name or local PyPy. Everything was configured properly. You should be connected with the remote computer at once. Once you are in any commands that are typed in your PowerShell prompt will be executed on the remote computer and the output will be displayed to you. Once you are done, you can end the remote session way using the exit PS session commandlets. Another way of using PowerShell promoting is by running a command on the guest without starting a session. To do so, you can use the invoked commands, commandlets, followed by the name or IP of your guests, the script block parameter and the command you want to execute within curly braces. The output will be displayed in your computer. In the same way, you can replace script block with the file path parameter to execute a script. Please note that the script must be on, are accessible to the local computer. If you get an error regarding the execution of the script, you must change the value of the execution policy on the guest computer to remote sign. Here is the command you need to use. To do that. You should now be able to execute scripts on the remote computer. Please note that when the info command command is used, PowerShell establishes a connection for only that command. The connection is closed when the command is complete and any variable or functions that were defined in the session would be lost. Finally, you can create a persistent session using the new PEA session commanded. With a persistent session, you can execute multiple commands that shared data remotely. To create a persistent session, use a new session commandlets and save us into a new variable. To interact directly with the remote computer, use either the enter PS session or the invoke command, a mindless, just like we did before. Here is an example of how a variable can be interacted with remotely using our persistent session. So let's first create our variable, and then let's modify it remotely. This would not have been possible with the invoke command, commandlets on its own without a persistent session. Because like we said before, a connection is established only for the command and any related data is deleted with irregular session. Summary. Powershell or voting is a useful feature that lets you run any PowerShell commandlets, e11 or many remote computers to enable PowerShell remote running on a machine that's on your domain, you must go over to the remote computer and type the enable PS remotely compile it into a PowerShell console with administrator privileges. To start an interactive session with your guest, use the Enter PEA session commandlets along with the name or local IP of your guessed, if everything was configured properly, you should be connected with the remote computer at once. That's it. You now know are motoring is and how it can be used. Make sure you practice on your own what you have learned thus far. Until then, see you in the next lecture. 24. Conclusion: Conclusion. This brings us to the end of the course. You now hopefully have the knowledge to complete a variety of tasks with PowerShell in an efficient and effective manner. Personally, learning how to use PowerShell was one of the best decisions I ever made, and I am very glad to have shared my knowledge with you. I really hope you've enjoyed this course. I've certainly enjoyed teaching it to you and make sure to use PowerShell often. So you do not forget we have learned until then. See you in the next course. Goodbye.