Browse by Tags

Tagged Content List
  • Blog Post: PowerTip: Remove Leading and Trailing Spaces with PowerShell

    Summary : Use the Trim() method to remove extraneous space from a String object. Is there an easy way to drop all spaces that are before or after a string in Windows PowerShell? Use the Trim() method to remove all spaces before and after a string from the output, for example: $Something='...
  • Blog Post: PowerTip: Display Message in 16 Colors

    Summary : Use Windows PowerShell to display a message in 16 colors. How can I use Windows PowerShell to easily display a message in 16 different colors to start my presentation with something a little different? Use the range operator to create 16 numbers. Pipe the numbers to the Foreach-Object...
  • Blog Post: PowerTip: Cause PowerShell to Wait for Specific Event

    Summary : Cause Windows PowerShell to wait for a specific event to be generated. How can I make my Windows PowerShell console halt until an event that I registered by using the Register-CimIndicationEvent cmdlet occurs? Use the Wait-Event cmdlet and specifiy the source identifier. For example,...
  • Blog Post: PowerTip: Find Extended Type Data in PowerShell Session

    Summary : Find extended type data in your current Windows PowerShell session. How can I find out what extended type data exists in my current Windows PowerShell session? Use the Get-TypeData cmdlet.
  • Blog Post: PowerTip: Change Value of Element in Array with PowerShell

    Summary : Learn how to use Windows PowerShell to change the value of an element in an array. How can I use Windows PowerShell to update one of the values in one of the elements of an array? Use the Item method to retrieve the element and assign a new value. Here is an example of updating the value...
  • Blog Post: PowerTip: Use PowerShell to Find Path for Processes

    Summary : Use Windows PowerShell to find the path of the executable for running processes. I noticed a process and I am unsure of what it does. How can I use Windows PowerShell to find more information? Look at the path to the executable to find information about a process. If it is legitimate...
  • Blog Post: PowerTip: Use Windows PowerShell to Open Word Document

    Summary : Learn how to use Windows PowerShell to open a Microsoft Word document. How can I open a Word document with Windows PowerShell? Use the New-Object cmdlet: $Filename='C:\HappyBirthdayEd.docx' $Word=NEW-Object –comobject Word.Application $Document=$Word.documents.open...
  • Blog Post: PowerTip: Find Array Members with Get-Member in PowerShell

    Summary : Learn to find members of an array with the Get-Member cmdlet in Windows PowerShell. I have an array of numbers: 1,2,3,4,5 that I assigned to variable $a . When I pipe it to Get-Member: $a | gm , all I see are members for int32 . How can I find the members of an array by using Get-Member...
  • Blog Post: PowerTip: Find WMI Classes Related to Services

    Summary : Use Windows PowerShell to find WMI classes related to services that reveal start mode. How can I use Windows PowerShell to find a WMI class that will help me identify how services are starting? Use the Get-CimClass cmdlet, use a wildcard character for the name, and specify StartMode as...
  • Blog Post: PowerTip: Use PowerShell to Cast to WMI UInt Value Type

    Summary : Use Windows PowerShell to cast to the WMI UInt value type. I am comparing data from WMI, and it seems strange. I found the value type is a UInt32 , and when I looked it up, I found that it is an unsigned 32-bit integer . How can I use Windows PowerShell to create one of these? Use [uint32...
  • Blog Post: PowerTip: Find WMI Classes by Using PowerShell

    Summary : Use Windows PowerShell to find WMI classes. I am searching for a WMI class to help me find information about Windows startup configuration. I am unsure of the class name. How can I use Windows PowerShell to help me find the class (assuming it exists)? Use the Get-CimClass CIM cmdlet that...
  • Blog Post: PowerTip: Find Value from PowerShell Hash Table

    Summary : Look up values from a Windows PowerShell hash table. How can I look up a specific value that is associated with a specific key in a Windows PowerShell hash table? Use the Item method and supply the key, for example: $hash = @{ 2 = "Removable disk" 3="Fixed local...
  • Blog Post: PowerTip: Use Tab to Complete WMI Class Names

    Summary : Use Tab completion to type WMI class names in Windows PowerShell. I am using WMI in the Windows PowerShell console and in the Windows PowerShell ISE, and I am having a hard time correctly typing the long convoluted class names. How can I simplify the process and be more accurate? Use...
  • Blog Post: PowerTip: New Lines with PowerShell

    Summary : Create new lines with Windows PowerShell. How can I use Windows PowerShell to add a new line between lines for my text output? Use the `n character, for example: PS C:\> "string with new line `n in it" string with new line in it Note If you need a carriage return...
  • Blog Post: PowerTip: PowerShell Tabs

    Summary : Understand Windows PowerShell tabs. How can I use Windows PowerShell to efficiently add 1, 2, or 3 tabs to a string? Use the `t character for a single tab. Use `t`t for two tabs, and multiply them for three or more (such as “`t”*3 ). Here are examples: PS C:\> "this...
  • Blog Post: PowerTip: Find How Many Days until PowerShell Summit Europe 2014

    Summary : Use Windows PowerShell to find how many days until Windows PowerShell Summit Europe in Amsterdam. How can I use Windows PowerShell to help me find how many days until the Windows PowerShell Summit Europe 2014 in Amsterdam? Use the New-TimeSpan cmdlet, and use Get-Date to specify the start...
  • Blog Post: PowerTip: Use Complete Name for PowerShell Cmdlet

    Summary : Use the complete name for a Windows PowerShell cmdlet. How can I ensure that I use the correct cmdlet in my Windows PowerShell session if I think there might be more than one with the same name? Use the complete name of the cmdlet—this includes the module name and the cmdlet name...
  • Blog Post: PowerTip: Use PowerShell to Copy Array

    Summary : Use Windows PowerShell to copy an array. How can I use Windows PowerShell to copy the contents of one array over another array? One way to do this is to use the Copy static method from the System.Array .NET Framework class, for example: PS C:\> $a = 1,2,3,4,5 PS C:\> $b =...
  • Blog Post: PowerTip: Reverse Array with PowerShell

    Summary : Use Windows PowerShell to reverse an array. How can I use Windows PowerShell to sort an array that is going in the wrong direction? Call the Reverse static method from the [array] class, for example: PS C:\> $a = 1,2,3,4,5 PS C:\> [array]::Reverse($a)
  • Blog Post: PowerTip: Use PowerShell to Sort Array

    Summary : Use Windows PowerShell to sort an array. How can I use Windows PowerShell to sort an array? Use the static Sort method from the [array] class, for example: $a = 1,2,4,5,3,6 [array]::sort($a)
  • Blog Post: PowerTip: Using PowerShell to Determine if Path Is to File or Folder

    Summary : Learn how to use Windows PowerShell to determine if a path is to a file or a folder. How can I use Windows PowerShell to determine if a path is to a file or a folder? Use the Get-Item cmdlet to get the object represented by the path. Then use the –Is operator to see if the object...
  • Blog Post: PowerTip: Use PowerShell to Set Primary and Secondary DNS Server Addresses

    Summary : Use Windows PowerShell to set the primary and secondary DNS server addresses for a client. I recently changed the IP address scheme for an entire subnet. How can I use Windows PowerShell to set the primary and secondary DNS server addresses for the client workstations? Use the Set-DNSClientServerAddress...
  • Blog Post: PowerTip: Hide Common Code in PowerShell ISE

    Summary : Learn how to hide common code in the Windows PowerShell ISE. How can I hide related code in the Windows PowerShell ISE to make it easier to troubleshoot and to read? Open the ISE, and in the script pane, begin a section with the #Region tag and a name. Then end the section with the #EndRegion...
  • Blog Post: PowerTip: Use Graphical Tool to Create PowerShell Commands

    Summary : Learn how to use a graphical tool to create Windows PowerShell commands. How can I use Windows PowerShell so that I can point-and-click at options that are available for a using a particular cmdlet? Use the Show-Command cmdlet and select the parameters you need, for example: Show-Command...
  • Blog Post: PowerTip: Use PowerShell to Change System Time

    Summary : Learn how to use Windows PowerShell to change the system time. The clock on my computer (running Windows 8.1) is 30 minutes slow. How can I use Windows PowerShell to move the system time up 30 minutes? Use the Set-Date cmdlet, create a TimeSpan object equal to 30 minutes, and supply it...