Tuesday, January 29, 2013

Powershell Quick Start



Get-Alias- complete list of available aliases

Get-Command - that returns a list of all the PowerShell cmdlets available to you

Format-List : is a cmdlet that takes information passed to it and then outputs that information in list view (that is, property values are displayed on separate lines rather than as columns in a table).
Eg:PS C:\scripts> Get-Command | Format-List

Format-Table : cmdlet can take pretty much any information and display it as a table rather than a list.

set-location c:\Windows

Get-ChildItem C:\Scripts –recurse

Set-ExecutionPolicy RemoteSigned
To run scripts from within Windows PowerShell you will need to change your security settings; by default, PowerShell only runs scripts signed by a trusted authority.

Get-Process
To get information about the properties and methods of an object retrieve an instance of that object and then “pipe” the object to the Get-Member cmdlet. For example, this command returns the properties and methods available when working with processes:  eg Get-Process | Get-Member

Get-Process 
To work with or display specified properties of a collection, pipe the returned results to the Select-Object cmdlet:
Eg Get-Process | Select-Object Name, Company


Where-Object {$_.Length -gt 200KB} | Sort-Object Length
To filter and sort objects . Sort-Object should typically appear on the right-hand side of a pipeline.
Eg1:
Get-ChildItem C:\Scripts | Where-Object {$_.Length -gt 200KB} | Sort-Object Length
eg2: Get-Service | Sort-Object Status | Format-Table
eg:3: $a = (Get-Process | Sort-Object ID)
 
You have a variable $a that contains a collection of data. You can sort that data, and sidestep the pipeline altogether, by using a command like this: eg: Sort-Object -inputobject $a



Some more must read for quick start

1)Running powershell
http://technet.microsoft.com/en-us/library/ee176949.aspx
 
2)Getting started with powershell
http://technet.microsoft.com/en-us/library/ee177003.aspx

and other links under those section of above links.


More references:




1) Windows PowerShell Quick Reference

http://www.microsoft.com/en-us/download/details.aspx?id=7097


2) Learn powershell
   http://blog.endjin.com/2012/03/an-omega-geeks-guide-to-learning-powershell/

3) Windows PowerShell Graphical Help File

Some issues and Solution
1)Issue unable to load snapin
Sol : some snapins are registered for 64 bit
in that use try powershell.exe at  C:\Windows\SysWOW64\WindowsPowerShell\v1.0 –
& some might work only for 32 bit then try powershell at C:\Windows\System32\WindowsPowerShell\v1.0)






No comments:

Post a Comment

Devops links

  Build Versioning in Azure DevOps Pipelines