Power Tips

Share |

Join PowerShell.com!
Subscribe to Feed

PowerShell eBook
Sign up for
Your PowerTip of the Day:

Award-winning PowerShellPlus


Admin Guide to PowerShell Remoting


Mastering PowerShell eBook

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
  • Accessing Function Parameters by Type

    Adding parameters to your functions is fairly easy. You can add a param() block and specify the parameters. But what if you wanted to assign values to different parameters based solely on type? Let's say you want a function that accepts both numbers...
  • Creating Your own Types

    Did you know that you can compile any .NET source code on the fly and use this to create your own types? Here is an example illustrating how to create a new type from c# code that has both static and dynamic methods: $source = @ ' public class Calculator...
  • Calculating Server Uptime

    Have you ever wanted to find out the effective uptime of your PC (or some servers)? The information can be found inside the event log. Here is an example on how to select and prepare event data and create a report. This even works remotely. function Get...
  • Getting Installed Updates

    PowerShell is great for parsing log files. Here is a function that extracts all installed Windows updates from an internal log file and returns the information as pure PowerShell objects. Have a look as this code uses a number of powerful parsing and...
  • E-mail-Address-Extractor via RegEx

    Regular expressions are extremely powerful - and complex. Fortunately, there are plenty of sources for good regular expressions that describe all kinds of patterns. This is how you turn a RegEx pattern into a regular expression engine: $regex = [ RegEx...
  • Accessing WMI Instances in One Line

    While you can use Get-WMIObject to query for WMI objects and then select the ones you are really after, you can also cast a WMI object path to a WMI object and get to that instance immediately. For example, the following accesses the WMI object representing...
  • Grouping with Script Blocks

    Group-Object creates groups based on object properties. For example, you could group processes by company or folder listings by extension: Dir $env:windir | Group-Object Extension Get-Process | Group-Object Company If the object has no property that reflects...
  • Replace Text in Files

    Often, some text will need to be replaced in a text file. That's easy with Get-Content and Set-Content - or not? Get-Content c:\ somefile.txt | Foreach-Object { $_ -replace 'old' , 'new' } | Set-Content c:\ somefile.txt If you try...
  • Sorting Multiple Properties

    Sort-Object can sort on multiple properties at the same time. Have a look: Get-Service | Sort-Object Status, Name This will list stopped services first, then running services. Within the two blocks, services are sorted by name. To reverse sort order,...
  • Discover Hidden Object Members

    Get-Member is a great cmdlet to discover object members, but it will not show everything: "Hello" | Get-Member You should add -force to really see a complete list of object members: "Hello" | Get-Member -force One of the more interesting...
  • Adding Extra Information

    Sometimes you may want to tag results returned by a cmdlet with some extra information, such as a reference to some PC name or a timestamp. You can use Add-Member to tag a note property to the result. This line gets all services and adds two new columns...
  • Making Objects Read/Write

    Whenever you pipe objects through Select-Object, you actually get a copy of the original object. All properties are now readable and writeable, so you can change the object properties in any way you like. This example reads memory information and then...
  • Creating Relative Dates

    To create relative dates like "10 days ago," there are two paths. Administrators often add or remove time spans created by New-Timespan: ( Get-Date ) - ( New-TimeSpan -days 10) Developers prefer object methods: ( Get-Date ). AddDays ( - 10)...
  • Create Remoting Solutions

    Whenever you use WMI (Get-WMIObject) to retrieve information, it's a snap to turn a local solution into a remotable solution. You can just add the parameter -Computername to Get-WMIObject. In a previous tip, you learned how to examine physical memory...
  • How Much RAM Do You Have?

    Ever wondered what type of RAM your PC uses and if there is a bank available to add more? Ask WMI! This example also converts the cryptic type codes into clear-text using hashtables to create new columns: $memorytype = "Unknown" , "Other"...
« First ... < Previous 72 73 74 75 76 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.