Powershell day 2

Day 2 Introduction to Windows Powershell.

Windows Powershell is a very powerful shell script to interact with windows.

Using windows Powershell you can access everything on windows system.

Some of the features we can achieve using Powershell:

  1. Active directory
  2. Exchange
  3. SQL Server Provider and Database Engine
  4. Registry
  5. Failure clustering
  6. Remote Desktop work
  7. Service Manager
  8. Virtual Machine
  9. IIS
  10. Windows administration
  11. Windows Server Backup

 

http://technet.microsoft.com/en-us/library/ee829690.aspx

http://en.wikipedia.org/wiki/Windows_PowerShell

There are 4 categories of commands in PowerShell:

Cmdlets :         These are built-in commands in the shell, written in a .NET language like C# or Visual Basic. Users can extend the set of cmdlets by writing and loading PowerShell snap-ins.

Functions:       Functions are commands written in the PowerShell language that are defined dynamically.

Scripts:            ps1 extension containing a collection of PowerShell commands.

Applications:    executables.

Cmdlets are the commands for Powershell, generally Powershell is build in such a way that it uses similar way of writing script like UNIX shell.

Command completion (tab) when you give half the command and tab it will automatically try to complete the command (like – intelisence). And next (tab) will give the next similar command

Eg.

Get-c(tab) will gives you “Get-ChildItem” and another (tab) will gives you “Get-Command”

There are some common commands which will run for windows scripting /Powershell

  1. Get-Command :To get all the list of commands.
  2. Get-Help: to get the help of the command you can use get-help

Eg. If you want to get information about particular command eg. Get-command

Ps:\> Get-help get-command

Will give you help about get-command

Comparison of cmdlets with similar commands(From Wikipedia*):-

Windows PowerShell
(Cmdlet)
Windows PowerShell
(Alias)
cmd.exe / COMMAND.COM
(MS-DOS, Windows, OS/2, etc.)
Bash
(Unix, BSD, Linux, Mac OS X etc.)
Description
Get-ChildItem gci, dir, ls dir ls List all files / directories in the (current) directory
Get-Content gc, type, cat type cat Get the content of a file
Get-Command gcm help which List available commands
Get-Help help, man help man Help on commands
Clear-Host cls, clear cls clear Clear the screen[Note 1]
Copy-Item cpi, copy, cp copy cp Copy one or several files / a whole directory tree
Move-Item mi, move, mv move mv Move a file / a directory to a new location
Remove-Item ri, del, erase, rmdir, rd, rm del, erase, rmdir, rd rm, rmdir Delete a file / a directory
Rename-Item rni, ren, mv ren, rename mv Rename a file / a directory
Get-Location gl, pwd cd pwd Display the current directory/present working directory.
Pop-Location popd popd popd Change the current directory to the directory most recently pushed onto the stack
Push-Location pushd pushd pushd Push the current directory onto the stack
Set-Location sl, cd, chdir cd, chdir cd Change the current directory
Tee-Object tee n/a tee Pipe input to a file or variable, then pass the input along the pipeline
Write-Output echo, write echo echo Print strings, variables etc. to standard output
Get-Process gps, ps tlist,[Note 2] tasklist[Note 3] ps List all currently running processes
Stop-Process spps, kill kill,[Note 2] taskkill[Note 3] kill[Note 4] Stop a running process
Select-String n/a find, findstr grep Print lines matching a pattern
Set-Variable sv, set set set Set the value of a variable / create a variable
Advertisements
This entry was posted in Powershell and tagged . Bookmark the permalink.

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