Sunday, 6 July 2014

Starting PowerShell from the Basic Commands !

This is the very basics of PowerShell.


Get-Help
You will be able to understand how to perform each and every command available in PS using help command. Before using powershell help you have to update the help with latest update. Update help is the new features available in PowerShell 3.0. Not available in previous version of PS. Update-help is the command used to update the help content. I am giving some example for updating help.

PowerShell 3.0 Updateable Help.
Below is the command to update help directly from Internet..


001
Update-help -force

I always recommend updating the PowerShell as it gives more detailed help as well as examples of cmdlets, so we can use the PowerShell itself as a guide for understanding the commands.

We need to run PowerShell as "Run as Administrator" (As the files will be stored under root file which is restricted by default) to perform the update

'Get-help Update-help' command provides more details about how to update help

Force is using to update the help file forcefully.












We can save the help file using save-help cmdlet. This will allows you to download the newest help files for Windows PowerShell and save in a specified directory. This feature lets you update the help file on the computer that do not have Internet availability.
Below is the cmdlet used to save the help-files and update from the saved place. We have to specify the UI Culture while downloading the help files. (Get-UICulture is the command to get the UICulture of the system)


001
002
Save-Help -UICulture en-US -DestinationPath C:\Users\vivek\PSHelp -Verbose
Update-Help -SourcePath C:\Users\vivek\PSHelp -Verbose

Get-Command

Can you remember all the cmdlets in powershell ???

If NO, get-command will help you to retrieve all the available powershell commands.If you remember any words in the command, you can easily retrieve the command. But it will not display the additional parameters and display all the command in console by default.

# Out-GridView : This cmdlet will display the output in  different windows and will help you to read it properly

001
002
003
Get-Command Get-Help
Get-command get-exe*

Get-member

Get-Member is an essential command for discovering more about a PowerShell objects.As you can see, powershell output shows us some of the default properties, not all. We can use get-member cmdlet to retrieve all the properties of an object. More over we will be getting all the methods of an object by using get-member.


001
Get-Process | Get-Member

GM is the alias for Get-Member

A cmdlet always consists of a verb and a noun, separated with a hyphen. Some of the verbs use for you to learn PowerShell is:
  • Get — To get something
  • Start — To run something
  • Out — To output something
  • Stop — To stop something that is running
  • Set — To define something
  • New — To create something

PowerShell's execution policy 

PowerShell's execution policy is a safety feature that controls the conditions under which PowerShell loads configuration files and runs scripts. This feature helps prevent the execution of malicious scripts.
  • Restricted - No scripts can be run. Windows PowerShell can be used only in interactive mode.
  • AllSigned - Only scripts signed by a trusted publisher can be run.
  • RemoteSigned - Downloaded scripts must be signed by a trusted publisher before they can be run.
  • Unrestricted - No restrictions; all scripts can be run.