Powershell

Testing Administrator Privileges

To test whether a script is run by an Administrator with full privileges (UAC elevated), here is an unusual approach that illustrates the enormous...

Creating Hard Links

Hard links are file "phantoms" in the NTFS file system. They make one file visible in multiple file system locations (within one volume)....

Showing Hidden Files in File Explorer

PowerShell can easily read and write to the Registry, the central store for Windows settings. Here's a function that can turn the display of...

Verbose Output for PowerShell Functions

To add on-demand verbose output to your PowerShell functions, make sure your functions support the common parameters by adding the CmdletBinding...

Copying Results to Clipboard

To easily copy cmdlet results to other applications, simply pipe them to clip.exe. Next, paste the results into whatever application you want:...

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

1 65 66 67 68 69 104