04 January 2015

Powershell v3 features



  • Ordered hash tables can be created by casting with [ordered] keyword:

    $hash = [ordered]@{firstname = 'John' ; lastname = 'Smith'}
  • Custom objects can be created more easy as hash table by casting with [PSCustomObject]
    it will be automatically ordered.

    $a = [PSCustomObject]@{firstname = 'John' ; lastname = 'Smith'}
  •  default parameters values can be set for cmdles.

    $PSDefaultParameterValues['Get-ADUser:Properties']='EmployeeID'

    will only be available in current session but can be added to profile and be loaded at start up.
    one disadvantage is that if you use that parameter in your comdlets the default value that was setup will be overwritten.
      
  • Count and Length property is available for all objects (even if the object is not an array).
    All objects can be indexed into with [ ]
    If the object already have an Count or Length property, they will remain unchanged,
  • ISE have now tabs - can be used for different remote sessions.

    tabs can be renamed: $psise.PowerShellTabs[0].DisplayName = 'Production Scripts'
    new tab can be opened: $PSISE.PowerShellTabs.Add()
  • in ISE explicit code regions can be used to allow collapsing between any two points

    #region some region description can be inserted here
    #endregion
  • ISE automatically highlight matching braces ( ) { } [ ] when cursor is in front of them.
  • current object in pipeline that use to be referred with $_ can also be referred with $PSItem variable.

No comments:

Post a Comment