Powershell

Displaying Path Environment Variables

The environment variable $env:Path lists all paths that are included in the Windows search path when you launch an application. Likewise,...

Finding Disk Partition Details

To view disk partitioning information, use WMI: Get-WmiObject -Class Win32_DiskPartition | Select-Object -Property * Next, pick the properties you...

Use a Lock Screen

With WPF, PowerShell can create windows in just a couple of lines of code. Here's a funny example of a transparent screen overlay. You can call...

Creating Temporary Password

Here's a chunk of code that creates random passwords of different lengths for you: $length = 8 $characters = [Char[]]((31..50) + (65..90) +...

Obfuscating Credentials

How can you securely embed confidential passwords in a PowerShell script? You can't. But you can make it harder for people to discover the...

Create a Folder Selector

To add a little glamour to your scripts, here are a few lines of code that display a folder selector dialog. When a user selects a folder, your...

Getting Folders by Prefix

Did you know that Group-Object can easily group elements by custom criteria? Here's a line that groups folders by their first three letters:...

Finding Known USB Drives

Did you know that Windows maintains a list of all USB storage devices ever hooked up to your machine? And it's simple to dump that list: $Path =...

Getting DLL File Version Info

Ever needed a list of DLL files and their versions? Get-ChildItem can get this information for you. You just need to unpack some properties like so:...

Executing Code Remotely

In a domain environment, PowerShell remoting is working almost out of the box. All you might have to do is enable Remoting on target machines...

Accessing All Users Desktop

Resolve-Path is an excellent cmdlet to find paths that have the same nesting level. For example, here's a really short script that creates a text...

Quickly Selecting Results in ISE

If you'd like to quickly select and copy results from the Console Pane of the PowerShell 3.0 ISE editor into your blog or favorite word...

Speeding Up Multiple WMI Queries

Whenever you run Get-WmiObject against a remote system, it will create a new connection. So if you query different WMI classes, each query will use...

Getting WMI IntelliSense

Get-WmiObject provides no IntelliSense for WMI classes, so you either need to know the WMI class name off hand, or use the parameter -List to search...

Listing "Real" Hard Drives

WMI can provide lots of information about a system, but sometimes it is just a bit too much. So when you query for logical disks, you often get back...

Improving Module Auto-loading

PowerShell 3.0 will auto-load modules as you have seen in a previous tip. However, with some modules, this technique may fail. Their cmdlets will...

Loading Modules Automatically

Beginning with PowerShell 3.0, PowerShell is smart enough to know which cmdlets are exported by which extension module. So you no longer have to...

Getting MAC Address Remotely

Here is an easy way to get the MAC address, even from a remote machine: Simply replace the IP address with the one you are interested in. You may...

Launching PowerShell as Different User

Once you pin PowerShell to your taskbar, you can always right-click the pinned PowerShell icon to open a jump list and launch PowerShell or the ISE...

Monitoring Log Files

Beginning in PowerShell 3.0, it is easy to monitor text-based log files in real-time. Try this: $Path = "$home\Desktop\testfile.txt"...

Keyboard Trick

In the PowerShell ISE 4.0 command pane, when you hold CTRL, you can then use ArrowUp to move out of the command line into the results area. ReTweet...

Getting Excuses Automatically

Tired of inventing lame excuses yourself? Then here's a script that gets you a new excuse any time you call Get-Excuse! All you need is Internet...

Capitalizing Words

To correctly capitalize words (making sure the first character is capitalized), you can either use regular expressions or a little system function....

Finding Default Outlook Profile

PowerShell can access COM objects like Outlook Application. These two simple lines return the current Outlook profile: $outlookApplication =...

1 63 64 65 66 67 104