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

Power Tips

Power Tips

Syndication

  • Removing Leading "0" in IP Addresses

    Leading "0" in IP addresses can cause confusion because many network commands interpret octets with leading "0" as octal numbers: # no leading "0": PS > ping 10.10.5.12 Pinging 10.10.5.12 with 32 bytes of data : ( ......
  • CIM-Cmdlets Work Against Old Windows Boxes

    The new CIM cmdlets require PowerShell v3, but you can still remotely target older boxes without PowerShell v3 or PowerShell at all. By default, CIM cmdlets use WSMan for remote connections. If you want to use the old DCOM technique, create a CIMSession...
  • New WMI Cmdlets with DateTime Support

    In PowerShell v3, to work with WMI you can still use the old WMI cmdlets like Get-WmiObject. There is a new set of CIM cmdlets, though, that pretty much does the same - but better. For example, CIM cmdlets return true DateTime objects. WMI cmdlets returned...
  • Finding Keyboard and Mouse

    You can use WMI to quickly find all details about your mouse and keyboard: PS > Get-WmiObject win32_PointingDevice | Where-Object { $_ . Description -match ' hid ' } PS > Get-WmiObject win32_Keyboard | Where-Object { $_ . Description -match...
  • Finding Built-In Variables Part 2

    In a previous tip we featured a piece of undocumented code that works in PowerShell v3 to list all built-in variables. Here is another approach that also works in PowerShell v2. It creates a fresh new runspace and dumps all variables. Since the runspace...
  • Adjust Text to Specific Length

    If you must make sure that a text has a fixed length and is neither shorter nor longer, here is the code to pad and cut the text to the desired length: $text1 = ' some short text ' $text2 = ' some very very very very long text ' $desiredLength...
  • Finding Built-In Variables

    Finding Built-In Variables [ psobject ] . Assembly . GetType ( ' System.Management.Automation.SpecialVariables ' ) . GetFields ( ' NonPublic,Static ' ) | Where-Object FieldType -eq ([ string ]) | ForEach-Object GetValue $null Once you...
  • Displaying MsgBox TopMost

    In a previous tip you learned how to load additional .NET assemblies. This enables you to display dialog boxes like a MsgBox, pretty much like in VBScript. You can even make the MsgBox stay on top of all other windows so it never gets covered and hidden...
  • Loading Additional Assemblies

    When you want to load additional .NET assemblies to extend the types of object you can use, there are two ways of loading them: the direct .NET approach and the Add-Type cmdlet. Both examples do the same and open a MsgBox from PowerShell: Direct .NET...
  • New WMI Help Topics in PowerShell 3.0 Released

    PowerShell 3.0 comes with two new help topics (among many others) that may be especially useful for those who work a lot with WMI (or would like to dive into it): PS > help about_WMI -ShowWindow PS > help about_WQL -ShowWindow "about_WMI"...
  • Using Open File Dialogs

    To spice up your scripts, PowerShell can use the system open file dialog, so users could easily select files to open or to parse. Here's the code to open the dialog and evaluate the dialog results: $dialog = New-Object -TypeName System.Windows.Forms...
  • Playing WAV files

    PowerShell can play WAV files, so you can add sound and special effects to your scripts (provided your system has a sound card): PS > $player = New-Object System.Media.SoundPlayer " $env:windir\Media\notify.wav " PS > $player . Play (...
  • Adding New Type Accelerators

    To access popular .NET types faster, PowerShell maintains a list of shortcuts called "type accelerators". That's why you can use the term "XML" for XML data instead of having to always write "System.Xml.XmlDocument":...
  • Discovering Date and Time Culture Information

    PowerShell automatically converts date and time information in various formats. If you'd like to know what formats are recognized by PowerShell, how these formats are defined, and what else your current culture defines, here is a one-liner that dumps...
  • Installing Local Printer

    WMI represents all locally installed printers with its class Win32_Printer, so you can easily look what's installed: PS > Get-WmiObject -Class Win32_Printer | Select-Object -Property * To add a new local printer, just add a new instance of Win32_Printer...
« First ... < Previous 26 27 28 29 30 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.