Power Tips

Share |

Join PowerShell.com!
Subscribe to Feed

PowerShell eBook
Sign up for
Your PowerTip of the Day:

Powershell Plus


13 Free SQL Tools from Idera


Free Ebook: Mastering Powershell

Welcome to the archive of tips delivered through Tobias' Tip of the Day RSS Feed and Your Power Tip of the Day email. Subscribe in the sidebar to get the latest tips!

Sort by: Most Recent | Most Viewed | Most Commented
  • Multiline-Input in ISE Editor

    If you'd like to enter long lines of code into the console panel in the new PowerShell 3.0 ISE, you can press SHIFT+ENTER. This will add a line break without sending the line to PowerShell yet. ReTweet this Tip!
  • Kindergarten-Mode

    To protect you from damages while playing with PowerShell on a productive system, set the ”WhatIf” mode as default: $WhatIfPreference = $true Now, instead of actively enabling the simulation mode by adding - WhatIf to a cmdlets’ parameter...
  • Combining Objects

    Sometimes it becomes necessary to consolidate two or more objects into one. So, how would you combine object properties into one object? In a previous tip we illustrated how you can convert an object into a hash table. In PowerShell 3.0, Add-Member is...
  • Using CIM Cmdlets Against PowerShell 2.0

    As you may have read, in PowerShell 3.0, there is a new family of cmdlets designed to improve the way we work with WMI. The powerful Get-WmiObject cmdlet may become obsolete over time. Get-CimInstance, for example, works very similar to Get-WmiObject...
  • Finding Newest or Oldest Files

    In PowerShell 3.0, Measure-Object can be applied not just to numeric data but to anything that is comparable. In PowerShell 2.0, this line would return the smallest and largest file size in your Windows folder: Get-ChildItem $env:windir | Measure-Object...
  • NULL values have a Count property

    In a previous tip we explained that in PowerShell 3.0, every object has a Count property now. This even includes null values: PS > $null . Count 0 This is so that when a command returns "nothing", you still can find out how many items you...
  • Displaying Object Standard Properties (Nicely)

    In a previous tip, we explained how you can add a custom data type to your own custom objects that you might want to return from a function, and then use PowerShell 3.0's new Update-TypeData to define the standard object properties. This approach...
  • "Count" Available in PowerShell 3.0

    Finally, the property Count is available on all objects in PowerShell 3.0. This solves a great problem because it allows you to count results even if they are not wrapped in an array. Have a look: PS > ( Get-ChildItem $env:windir \ * . txt ) . Count...
  • Removing Empty Object Properties (All Versions)

    In a previous tip we showed how you can remove all empty properties from an object and also sort its properties alphabetically. The code required PowerShell 3.0 features. Here is a variation that runs on all PowerShell versions. Again, it takes a BIOS...
  • Removing Empty Object Properties

    Objects hold a lot of information and often, properties can also have null values. To reduce an object to only those properties that actually have a value, you can convert the object into a hash table and remove all empty properties, then turn the hash...
  • Controlling Object Property Display

    When you create functions that return custom objects, there is no way for you to declare which functions should display by default. PowerShell always displays all properties, and when there are more than 4, you get a list display, else a table: function...
  • Logging Input Commands

    If you'd like to maintain a log file with all the commands you entered interactively - in the PowerShell console as well as in the ISE editor - here is an easy way: Simply redefine the built-in prompt function. It is responsible for writing the prompt...
  • Creating Objects in PowerShell 3.0 (Fast and Easy)

    In PowerShell 3.0, you can cast a hash table to a PSCustomObject type to easily generate your own objects: $content = @ { Name = "Weltner" FirstName = ' Tobias ' id = 123 } [ PSCustomObject ] $content The result is an object : Name FirstName...
  • Protecting Functions

    To prevent a function to be redefined or overwritten, you can write-protect it: function Test-Function { ' Hello World! ' } Set-Item -Path function : Test - function -Options ReadOnly From this point, your function cannot be overwritten. However...
  • Creating New Objects the JSON way

    There are numerous ways how you can create new objects that you may use to return results from your functions. One way is using JSON, a very simple description language. It is fully supported in PowerShell 3.0. Have a look: PS > $content = ' {"Name"...
« First ... < Previous 59 60 61 62 63 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.