Power Shell – The very basics

I am also beginner to the power shell , so let us learn together.

If you need video tutorials, search for “scripting guy, Ed Wilson”. I went through the videos to get a clear concept. There are 5 short videos, try to practice, the same time you watch the videos. The only way you remember things will be by doing it yourself. (At least that is the only way i learn anything).

Powershell scripts will have the extension PS1. You can create any script by yourself in notepad and save it as filename.ps1 extension and it can be executed from the power shell.

By default power shell does not let you execute scripts on the system.
First, we have to check the existing set up on our computer.

NOTE : ignore double quotes when you type in the commands in power shell.

Open powershell and type “get-execution policy -list”
This will list the scope and the execution policy for user/computer/process, etc.
For example, to provide script execution right to current logged on user, use the following command,
set-executionpolicy -scope currentuser remotesigned

Remote signed is the preferred option. You have other options too like bypass, restricted, undefined, etc.

Use the get command to see if the above command has been applied ,
get-execution policy -list

Now you can see that the current user has been set to execute remote signed scripts.

SERVICES

get-service *  command will list all available services (running and stopped).
To get information about on particular service ie “wuauserv”,
get-service wuauserv . This will list the name, display name and status of the service wuauserv.

If you need more details about a service,
get-service wuauserv | format-list * — Gives you a detailed information about the service.

To list only services that are running,
get-service | where {_.status -eq ‘running’}

To list services that are stopped,
get-service | where {_.status -eq ‘stopped’}

This will list all services that are not running
get-service | where {_.status -ne ‘running’}

HISTORY

To see history of commands typed, just type ” h “. This will show all commands you have typed. I do not remember the exact number of commands it keeps, but its quite big. The good thing about history is that you donot need to type the whole big command again and again. For eg, to run the command 5 in history, type invoke-history 5 . That’s it.

Get-History | Format-List -Property * – This will list all commands executed with the date, time and execution status of the command.

 

EXAMPLES/HELP

To get help or examples just type get-help get-service -examples. Powershell will show you examples on how the get-service can be used.

PROCESS

For example, type notepad in power shell and it will open a notepad. Open one more notepad. So, now you have 2 process named notepad running on your system. To get details about the process notepad,

get-process notepad.

It will give you detailed information like , id, name and other details. No we have  2 process notepad, one with id 1234 and other with id 7890. To stop a process, we need to enter the id with the command , otherwise it will stop all process name d notepad.

stop-process 1234    — will kill only the process with the id 1234.

get-process notepad | format-list *     — will give you detailed view for each of the notepad process. For example, you prefer to check the time the process was started, you can execute the command and pipe it to filter the required details.

get-process notepad | format-list id, starttime

 

 

Will be updated soon…

 

 

 

 

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s