Windows Commands & Basic PowerShell Commands.md - Juan-bit94/Ops401D10 GitHub Wiki

Windows Commands

Basic Windows Commands

  • One reason why people tend to get confused by PowerShell, well, especially when they haven't really worked with it a whole lot, it is because it includes many common shell commands that are found in the Windows command prompt. That cmd.exe or DOS commands.
  • Now under the hood these are just shortcuts or aliases to PowerShell cmdlets. In much the same way Windows allows you to create shortcuts to items which point to an actual file or executable, PowerShell has aliases, many that ship with PowerShell, and map to familiar command names. For example, when you use dir, you are actually running the PowerShell cmdlet get-childitem.
  • Now lets look at cd, now once again, these are aliases that map to some other functionality that's built into PowerShell, some cmdlet. So cd, which we're familiar with in DOS as change directory.

Basic PowerShell Commands

  • This portion will explain several common PowerShell commands. Now PowerShell commands or cmdlets use a verb noun structure. its common and consistent throughout the entire set of PowerShell cmdlet names.
  • This portion will show you a few of the common ones. The ones that you'll be using very quickly when you start working with PowerShell. And it's important to note that there are long names and short names for PowerShell cmdlet names.
  • So you got your long name, like get-location. And you have a short version, which is usually uses the first letter of each of the verb and the noun. So get-location would be gl.
    • The cmdlet: get-location shows us the current path.
    • The cmdlet short version: gl also shows us the current path.
  • Knowing this, you can get around quickly in PowerShell by understanding that relationship of how the short names work. Now let's go ahead and change our folder or directory.
    • The cmdlet: set-location c:\new This puts us inside that directory.
    • The cmdlet short version: sl c:\new we could use the short version
  • To list the contents of the directory, we use the ls command.
  • Lets say you have a file in the directory you want to move, to do that you run the following.
    • The cmdlet: *move-item text1.txt c:*
    • The cmdlet above uses the name of the file and then you put the path to where you will move them.
  • If you wanted to create a new item, you use new-item, or just ni
    • new-item text2.txt
    • This text file will not be visible (created) in the directory.
  • If you want to remove an item. you use the remove-item cmdlet
    • remove-item text2.txt
    • The text2.txt file will be removed.