PowerShell Basics: Difference between revisions

From ITCwiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 6: Line 6:
date.
date.


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


[[File:get-date.jpg]]
[[File:get-date.jpg]]


this will display a manual on how to use this command and state how to use it.
-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  
another command very common to use is the ability to check current processes on the  
Line 19: Line 19:
[[File:get-process.jpg]]
[[File:get-process.jpg]]


full list of all the running processes.
-full list of all the running processes.


some of the more powerful commands like set-alias can create custom commands for  
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-
current commands. for example we will be using the command we used in the start "get-
date" to display the date and time.
date" to display the date and time.
Line 29: Line 29:
[[File:date.jpg]]
[[File:date.jpg]]


now when i enter the command "date" it will prompt the same info as get-date
-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  
congrats now you have the power to create your own aliases towards commands but wait we  
Line 38: Line 38:
[[File:get-process more.jpg]]
[[File:get-process more.jpg]]


as you can see not all of the data has been listed but why? that's because the  
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.  
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  
by pressing space bar more information can be displayed. so we have successfully piped 2  
Line 44: Line 44:
for another.
for another.


displaying the content of files can come in handy with Powershell but first we  
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  
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  
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  
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  
doing something really boring like "this is a test file".  
Powershell and type in the command get-content C:\test.txt.
 
once that is done move back to Powershell and type in the command get-content C:\test.txt.
 
[[File:get-content.jpg]]
 
if everything goes correctly Powershell should of displayed the text inside your text  
if everything goes correctly Powershell should of displayed the text inside your text  
file.
file.


location location location something everyone loves to use in a command based system.
changing the location where you are present is as easy as entering:


set-location c:\
set-location c:\
set-location.pic
 
[[File:set-location.jpg]]


will send you right to the root of the C drive.
will send you right to the root of the C drive.
Line 63: Line 68:


command get-childitem
command get-childitem
get-child.pic
 
[[File:get-child.jpg]]


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


this is just a basic introductory of Powershell and its power to function with  
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  
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  
format-table which can take the output of a file and display it as a table.with the  

Latest revision as of 09:21, 26 July 2010

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.