powertips

Three Most Useful ISE Tricks

If you use PowerShell 3.0 and the ISE editor, then here are the three most useful tricks you should know: 1. Press CTRL+J to open a list of...

Vertical Grid View

You can always pipe objects to Out-GridView and get a nice extra window with all of the object properties lined up as table. That's useful if...

Go to Function Definition on F12

If you are into writing long and complex PowerShell code with a lot of functions, then this one is for you. In other development environments, when...

Finding Type Accelerators

PowerShell maintains a list of shortcuts for .NET types to make coding more convenient for you. For example, to convert a string to a DateTime type,...

Returning Multiple Values

A PowerShell function can return multiple values. To receive them, simply assign the result to multiple variables: function Get-DateTimeInfo { #...

Get Quotes From the Webservices

There are plenty of free webservices around, and provided you have direct Internet access (no proxy), you can use New-WebServiceProxy to access...

Using Safe Cmdlets Only

Let's assume you want to set up a restricted PowerShell v3 console that just provides access to Microsoft cmdlets with the verb Get. One way to...

Finding Published Printers

Finding printers that have been published in your Active Directory becomes trivial with Windows 8 or Server 2012. PS> Get-Printer -ComputerName...

Get CPU Load

To get the average total CPU load for your local system or a remote system, use Get-Counter. The example below returns the average total CPU load...

Calling WMI Methods with CIM Cmdlets

It can be very useful to call WMI methods, for example to create new shares, but in PowerShell v2 you had to know the names and exact order of...

Listing Power Plans

There is a somewhat hidden WMI namespace that holds WMI classes you can use to manage power plans. The code below lists all power plans on your...

Mixing DCOM and WSMan in WMI Queries

Using the new CIM cmdlets in PowerShell v3, you can run remote WMI queries against multiple computers using multiple remoting protocols. The sample...

New Operator -In

In PowerShell v3, you can use a new simplified syntax for Where-Object. Both lines below list all files in your Windows folder that are larger than...

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...

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...

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...

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...

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...

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...

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...

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 =...

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...

1 59 60 61 62 63 98