PowerShell Basics

From ITCwiki
Jump to navigation Jump to search

Powershell is a new command line based program created by Microsoft. this is a simple walk through to give a new user to Powershell a easy to understanding and command base to use in the real world. if you have ever used a Linux based system Powershell is very similar in the approach to commands. first we can take a look at the Get-date command which displays the current time and date.

-now we can use the get-date command with the man command like this:

Get-date.jpg

-this will display a manual on how to use this command and state how to use it.

another command very common to use is the ability to check current processes on the computer.

get-proccess

Get-process.jpg

-full list of all the running processes.

some of the more powerful commands like set-alias can create custom commands for current commands. for example we will be using the command we used in the start "get- date" to display the date and time.

set-alias date get-date

Date.jpg

-now when i enter the command "date" it will prompt the same info as get-date

congrats now you have the power to create your own aliases towards commands but wait we can go to a even crazier level of commands by piping 2 commands in a row like so.

get-process | more

Get-process more.jpg

as you can see not all of the data has been listed but why? that's because the more command will only display as much information as the screen can handle at a time. by pressing space bar more information can be displayed. so we have successfully piped 2 commands in a row.the limitations of the set-alias command can only replace 1 command for another.

displaying the content of files can come in handy with Powershell but first we need to create a simple text file somewhere on your machine to be able to complete this command. i just created mine on the C: drive root for easy access and also i named mine test.txt. then after you create the file put some text into it anything you wish.im doing something really boring like "this is a test file".

once that is done move back to Powershell and type in the command get-content C:\test.txt.

Get-content.jpg

if everything goes correctly Powershell should of displayed the text inside your text file.

changing the location where you are present is as easy as entering:

set-location c:\

Set-location.jpg

will send you right to the root of the C drive.

then we would like to view the current files inside this directory we would use the

command get-childitem

Get-child.jpg

combining the 2 commands location and childitem gives you the power to move up and down through the directories of the file system.

this is just a basic introductory of Powershell and its power to function with the command line. there are many more commands not covered in this section such as format-table which can take the output of a file and display it as a table.with the creation of Powershell being based off the Linux command line the power of Powershell is endless and in the long run this will most likely replace command prompt in the years to come so you better learn the basics.