PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Forum experts available to answer your PowerShell questions

Power Tips

Power Tips

Syndication

Archives

  • Ad-hoc Debugging in PowerShell ISE

    Beginning with PowerShell 5.0, you can break into the debugger any time (in the PowerShell ISE). Simply press CTRL+B to invoke the debugger while a script runs. The next time a script takes longer than expected, try CTRL+B and have a look what it was...
  • Revealing Function Source Code

    Many of the PowerShell commands are made out of functions. Here is how you can peek into the source code of any function: ( Get-Command Test-NetConnection ) . Definition Just make sure the command you want to examine does exist, and is a function. Test...
  • Finding Useful .NET Types

    You may have heard about "type accelerators": they are shortcuts for the long .NET type name: PS> [XML] IsPublic IsSerial Name BaseType -------- -------- ---- -------- True False XmlDocument System.Xml.XmlNode PS> [XML].FullName System...
  • Automatic Unrolling Can Fail

    Beginning with PowerShell 3.0, there is a new feature called "Automatic Unrolling": when you specify a property or method on an array, then the property or method is called on all elements of that array: ( Get-Process ) . Name Unless you specify...
  • New Where-Syntax

    In PowerShell 4.0 and better, there is a new alternative to the Where-Object cmdlet: $all = Get-Service $all | Where-Object { $_ . Status -eq ' Running ' } $all . Where { $_ . Status -eq ' Running ' } The Where() method is special and...
  • Create New XML Item Programmatically

    In a previous tip we explained how you can clone an existing XML item to add a new item. This works only when there are already some items in the XML file that you can clone. To add new items from scratch, you can also programmatically add items. Before...
  • Remove an Item from an XML Document

    Removing items from an XML document is almost trivial: you use XPath to identify the node you want to remove, then remove it. Once you save the XML document, you get a new XML file without the item you wanted to get rid of. Before you play: In a previous...
  • Adding New Nodes to an XML Document

    If you need to add new items to an XML document that already contains such items, the easiest way is to search for an existing item, then clone it. You can then update the information in the cloned item and insert it into the XML document. Before you...
  • Updating XML Content Using XPath

    You can use Select-Xml to select content from an XML file, and then change or update its values. This is very powerful. You just need to get familiar with the XPath query language. Before you play: In a previous tip we showed how to create a new XML file...
  • Updating XML Content

    If you need to make changes to an existing XML document, for example to update inventory data, the easiest way is to load the document into an XML object. You can then use default PowerShell cmdlets to find the node you want to change, and change it....
  • Reading XML Content

    Reading XML formatted text is easy when you use an XML object for it. With its method Load(), you can read in content from a file path or a URL. In a previous tip we showed how to create a new XML file from scratch. This XML document is used in the next...
  • Designing XML Documents

    Today we start a little mini series about XML. To create sample data to play with, you will first create a well-formed XML. While you can create XML documents with text operations manually, this leaves room for mistakes. A better way is to use the specialized...
  • Finding Out UTC Time

    When you work in a global environment, it sometimes becomes necessary to translate the local time to UTC (Universal Time). The conversion is done by ToUniversalTime(). This method is part of any DateTime object. In this example, your local time is translated...
  • Fast String Operations

    String concatenation is a frequent thing in scripts but when you use the "+=" operator to append text to a string, this slows down your script considerably. A much better approach is to use a StringBuilder object to manipulate the string content...
  • Parse an Exact Date

    If you need to parse a date or time information out of raw text, and if the date and time format does not adhere to the standards of your operating system, then you can use a template and define the date and time pattern yourself. Have a look #requires...
« First ... < Previous 3 4 5 6 7 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.